无法在主视图控制器和弹出视图之间传递消息
我似乎无法在主视图控制器和弹出视图(iPad)内显示的表视图控制器之间进行任何类型的通信。
我以通常的方式在导航控制器内设置表视图:
// create popover
if (self.popoverController == nil) {
filesViewController = [[[MyTableViewController alloc] initWithFiles:fileList] autorelease];
UINavigationController *navCtrl = [[[UINavigationController alloc] initWithRootViewController:filesViewController] autorelease];
self.popoverController = [[UIPopoverController alloc] initWithContentViewController:navCtrl];
self.popoverController.delegate = self;
// resize popover
self.popoverController.popoverContentSize = CGSizeMake(320.0, 44 + [fileList count] * 44);
}
一切正常,我将文件名数组(fileList)传递到表视图中,该数组作为数组保存在表视图中称为文件列表。表视图显示文件名,当用户选择一个文件名时,我想将该文件名传递回主视图控制器。但是,我无法获得从表视图的 didSelectRowAtIndexPath 方法返回到主 VC 的任何通信。我尝试了各种不同方向的出口,并且尝试在 didSelectRowAtIndexPath 中创建一个新对象来处理来自表视图的文件名。我可以将文件名传递给新对象,但是当我尝试将其发送到 Main VC 时,它再次为空。当弹出窗口处于活动状态时,我发送到主 VC 的所有内容都显示为空。
- (void)popoverControllerDidDismissPopover:(UIPopoverController *)popoverController {
NSLog(@"%@", handler.addressForImageFile);
self.popoverController = nil;
[self.popoverController release];
}
是否有某种原因导致我的主 VC 无法从表视图中获取除空对象之外的任何内容?我花了几天时间尝试很多不同的事情。我觉得我对弹出窗口的工作原理的了解存在一些根本性的差距。当从表视图中选择字符串时,肯定有一种简单的方法可以将字符串发送回我的主 VC?
非常感谢您的帮助!
I'm seem unable to get any kind of communication going between my Main View Controller and a Table View Controller which is being displayed inside a Popover View (iPad).
I'm setting up the Table View inside a Navigation Controller in the usual way:
// create popover
if (self.popoverController == nil) {
filesViewController = [[[MyTableViewController alloc] initWithFiles:fileList] autorelease];
UINavigationController *navCtrl = [[[UINavigationController alloc] initWithRootViewController:filesViewController] autorelease];
self.popoverController = [[UIPopoverController alloc] initWithContentViewController:navCtrl];
self.popoverController.delegate = self;
// resize popover
self.popoverController.popoverContentSize = CGSizeMake(320.0, 44 + [fileList count] * 44);
}
Everything is working fine, and I'm passing an array of file names (fileList) into the Table View, which is held in the Table View as an array called listOfFiles. The Table View displays the filenames, and when one is selected by the user I want to pass that filename back to the Main View Controller. However, I cannot get any communication going back from the Table View's didSelectRowAtIndexPath method to the Main VC. I've tried all sorts of outlets going in various directions, and I've tried creating a new object in didSelectRowAtIndexPath to handle the filename coming from the Table View. I can pass the filename out to the new object, but when I try to send that into the Main VC it is null again. Everything I send to my Main VC while that popover is active comes up as null.
- (void)popoverControllerDidDismissPopover:(UIPopoverController *)popoverController {
NSLog(@"%@", handler.addressForImageFile);
self.popoverController = nil;
[self.popoverController release];
}
Is there some reason why my Main VC won't get anything but null objects from my Table View? I've spent days trying so many different things. I feel like there's some fundamental gap in my knowledge of how popovers work. Surely there is a simple way to send a string back to my Main VC when it is selected from the Table View?
Thanks so much for any help!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
可能有更好的方法来做到这一点,但根据传递字符串的目标,一种方法可能是使用 NSUserDefaults。
There's propably a much better way to do this, but depending on the goal of passing the string, one way could be to use NSUserDefaults.