如何将数据传递给通过“[[UINavigationController alloc] initWithRootViewController:newItemController];”模态呈现的子 UINavigationController?
这就是创建子 Controller 的方法(即本例中的 newItemController),它是通过 UINavigationController initWithRootViewController 方法初始化的,因此这里似乎无法调用自定义的 newItemController init 方法?也无法访问 newItemController 实例本身来调用自定义的“setMyData”类型方法?
NewItemController *newItemController = [NewItemController alloc];
newItemController.delegate = self;
UINavigationController *navController = [[UINavigationController alloc] initWithRootViewController:newItemController];
[self.navigationController presentModalViewController:navController animated:YES];
最佳答案
您问题中的代码缺少调用 NewItemController 的 init。
例如:
NewItemController *newItemController = [[NewItemController alloc] init];
现在,当您创建 NewItemController 时,您可以创建自己的 init:
-(id)initWithStuff:(NSString *)example {
self = [super init];
if (self) {
// do something with the example data
}
return self;
}
或者您可以将属性添加到 NewItemController 类
// header file
@property (nonatomic, copy) NSString *example;
// .m file
@synthesize example;
// when you create the object
NewItemController *item = [[NewItemController alloc] init];
item.example = @"example string data";
关于iphone - 如何将数据传递给以模态方式呈现的子 UINavigationController(即通过 initWithRootViewController),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5447538/