UIPopoverController + UINavigationController =委托问题

时间:2011-07-18 15:54:55

标签: ios delegates uinavigationcontroller uipopovercontroller

我有两个视图设置(在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];
    }

}

1 个答案:

答案 0 :(得分:1)

SubZone1iPadController中创建弹出窗口时,DetailView的实例不存在,因此您无法直接从DetailView设置其委托属性。

一个选项是将委托属性添加到iPadRootViewController,您可以在zoneListButtonController方法中设置。然后,当ipadrootviewController创建SubZone1iPadController时,请传递代理。


因此,在ipadrootviewControllerSubZone1iPadController中,添加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];
}