我有两个视图设置(在TabBar中)。带有按钮的DetailView,该按钮使用NavigationController + UITableView(RootView)从CoreData加载数据来调用PopOver。我在将数据从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];
}
}
答案 0 :(得分:1)
在SubZone1iPadController
中创建弹出窗口时,DetailView
的实例不存在,因此您无法直接从DetailView
设置其委托属性。
一个选项是将委托属性添加到iPadRootViewController
,您可以在zoneListButtonController
方法中设置。然后,当ipadrootviewController
创建SubZone1iPadController
时,请传递代理。
因此,在ipadrootviewController
和SubZone1iPadController
中,添加delegate
属性:
@property (nonatomic,assign) id <SubZone1Tap> delegate;
然后,在zoneListButtonController
方法中,在iPadRootViewController
上设置委托属性:
ipadrootviewController = [[iPadRootViewController alloc] init...
ipadrootviewController.delegate = self;
然后,ipadrootviewController
创建SubZone1iPadController
:
SubZone1iPadController *sz1 = [[SubZone1iPadController alloc] init...
sz1.delegate = self.delegate;
[self.navigationController pushViewController:...
[sz1 release];
最后,在DetailView
中,确保实现了委托方法。例如:
-(void)SubZone1Tap:(NSString *)name
{
NSLog(@"SubZone1Tap, name = %@", name);
//dismiss the popover if that's what you need to do...
[controladorPopOver dismissPopoverAnimated:YES];
}