首页 > 解决方案 > 是否可以通过 Foundation 的 NSNotificationCenter 传递 .net 数据?

问题描述

我在 Xamarin 上开发一个 .net 移动跨平台应用程序。

我想将数据从 ViewController A 发送到 ViewController B。在我的 ViewController A 中,我有一本字典。在我的 ViewController B 中,我想创建/编辑一个键/值对并将其添加回我的 ViewController A 中的字典。

为此,我想我使用 NSNotificationCenter。

但是,NSNotificationCenter 只允许将数据作为 NSObject(来自 Foundation 框架)传递。我需要发送的数据来自 .net Framework Dictionary(来自 System.Collections.Generic)。

实现这种数据传输的最佳实践是什么?

我已经尝试过在 .net 和基础框架之间进行明确的数据转换,并做一些诸如“NSObject.FromObject(keyValuePair)”之类的事情。不知道能不能逆向操作...

标签: c#xamarinnsnotificationcenternsobjectnsnotifications

解决方案


推荐阅读