objective-c - 在两个 View Controller 之间传递字典?

标签 objective-c ios cocoa-touch

我有一个应用程序,其中有一个 web 服务调用,该调用将数据作为字典返回。我想在另一个 View Controller 中访问此字典以将值加载到表中。

谁能演示如何将这个响应字典从一个 View Controller 传递到另一个 View Controller ?

最佳答案

您可以在 AnotherViewController 中定义一个 NSDictionary 属性,并从之前的 Controller 中设置它。下面我将给出一个简短的例子。

//.h
@interface AnotherViewController {

  NSDictionary *data;
}
@property(nonatomic,retain) NSDictionary *data;
@end

//.m
@implementation AnotherViewController
@synthesize data;

现在从当前 Controller 开始,在初始化 AnotherViewController 之后,您可以在呈现之前设置字典。

AnotherViewController *controller = [[AnotherViewController alloc] init];
controller.data = myCurrentDictionary;

现在 AnotherViewController 有一个 data 属性,其值为之前的 Controller 。

希望这对您有所帮助。

关于objective-c - 在两个 View Controller 之间传递字典?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10991743/

相关文章:

ios - 如何使用高度计? (增减法)

ios - 在 iOS 的 Scrollview 顶部的 CATiledLayer 中缩放和平移 pdf 绘图后更正触摸位置

iphone - 配置配置文件和 xcode 构建

ios - 如何将 UITableViewCell 显示为选中状态并仍然接收 didDeselectRowAtIndexPath

objective-c - 在 iOS 上,有没有更快的方法来获取 mainBundle 资源的 URL?

objective-c - 带索引的 UIViewController

objective-c - 将 Objective-C 中字符串中的整数相加

ios - iPhone 4s (8.4.1) 的 linphone 库中的 Sigabart 错误

ios - UIScrollView 与带有 UITextFields 的 TableView

iphone - 如何阻止 NSNotification 中的观察者调用两次?