UIPopoverController + UINavigationController = 委托问题
我有两个视图设置(在 TabBar 内)。 DetailView 带有一个按钮,该按钮调用带有 NavigationController+UITableView (RootView) 的 PopOver,从 CoreData 加载数据。我在将数据从 UITableView 传递到 DetailView 时遇到问题。我有一个在 RootView 中声明并在 DetailView 中使用的协议。
这是我用来从按钮创建 PopOver 的代码,因为我认为我有一些委托问题。任何帮助都会很棒,
- (IBAction)zoneListButtonController
{
if (self.controladorPopOver == nil) {
ipadrootviewController = [[iPadRootViewController alloc] initWithNibName:@"iPadRootView" bundle:[NSBundle mainBundle]];
UINavigationController *ipadnavController = [[UINavigationController alloc]
initWithRootViewController:ipadrootviewController];
UIPopoverController *popover = [[UIPopoverController alloc] initWithContentViewController:ipadnavController];
self.controladorPopOver = popover;
popover.delegate = self;
self.title = @"Countries";
popover.popoverContentSize = CGSizeMake(320, 300);
[self.controladorPopOver presentPopoverFromRect:CGRectMake(112, 20, 86, 27) inView:self.view permittedArrowDirections:UIPopoverArrowDirectionUp animated:YES];
[ipadnavController release];
[controladorPopOver release];
}
}
I have two views setup ( inside a TabBar). The DetailView with a button that calls a PopOver with a NavigationController+UITableView (RootView) loading data from CoreData. I have a problem passing data from the UITableView to the DetailView. I have a protocol declared in RootView and used in the DetailView.
Here is the code I use to create the PopOver from the button because I think I have some delegate issues. Any help will be amazing,
- (IBAction)zoneListButtonController
{
if (self.controladorPopOver == nil) {
ipadrootviewController = [[iPadRootViewController alloc] initWithNibName:@"iPadRootView" bundle:[NSBundle mainBundle]];
UINavigationController *ipadnavController = [[UINavigationController alloc]
initWithRootViewController:ipadrootviewController];
UIPopoverController *popover = [[UIPopoverController alloc] initWithContentViewController:ipadnavController];
self.controladorPopOver = popover;
popover.delegate = self;
self.title = @"Countries";
popover.popoverContentSize = CGSizeMake(320, 300);
[self.controladorPopOver presentPopoverFromRect:CGRectMake(112, 20, 86, 27) inView:self.view permittedArrowDirections:UIPopoverArrowDirectionUp animated:YES];
[ipadnavController release];
[controladorPopOver release];
}
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
当您在
DetailView
中创建弹出窗口时,SubZone1iPadController
的实例不存在,因此您无法直接从DetailView
设置其委托属性。一种选择是将委托属性添加到
iPadRootViewController
中,您可以在zoneListButtonController
方法中设置该属性。然后,当ipadrootviewController
创建SubZone1iPadController
时,传递委托。因此,在
ipadrootviewController
和SubZone1iPadController
中,添加一个delegate
属性:然后,在
zoneListButtonController
方法中,设置 delegateiPadRootViewController
上的属性:然后,在
ipadrootviewController
创建SubZone1iPadController
的位置:最后,在
DetailView
中,使确保委托方法已实现。例如:An instance of the
SubZone1iPadController
doesn't exist when you create the popover inDetailView
so you can't set its delegate property directly from theDetailView
.One option is to also add the delegate property to the
iPadRootViewController
which you can set in thezoneListButtonController
method. Then, whenipadrootviewController
creates theSubZone1iPadController
, pass along the delegate.So in both
ipadrootviewController
andSubZone1iPadController
, add adelegate
property:Then, in the
zoneListButtonController
method, set the delegate property oniPadRootViewController
:Then, where
ipadrootviewController
createsSubZone1iPadController
:Finally, in the
DetailView
, make sure the delegate method is implemented. For example: