UIPopoverController + UINavigationController = 委托问题

发布于 2024-11-24 13:21:50 字数 1223 浏览 1 评论 0原文

我有两个视图设置(在 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

梦一生花开无言 2024-12-01 13:21:50

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

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

因此,在 ipadrootviewControllerSubZone1iPadController 中,添加一个 delegate 属性:

@property (nonatomic,assign) id <SubZone1Tap> delegate;

然后,在 zoneListButtonController 方法中,设置 delegate 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];
}

An instance of the SubZone1iPadController doesn't exist when you create the popover in DetailView so you can't set its delegate property directly from the DetailView.

One option is to also add the delegate property to the iPadRootViewController which you can set in the zoneListButtonController method. Then, when ipadrootviewController creates the SubZone1iPadController, pass along the delegate.

So in both ipadrootviewController and SubZone1iPadController, add a delegate property:

@property (nonatomic,assign) id <SubZone1Tap> delegate;

Then, in the zoneListButtonController method, set the delegate property on iPadRootViewController:

ipadrootviewController = [[iPadRootViewController alloc] init...
ipadrootviewController.delegate = self;

Then, where ipadrootviewController creates SubZone1iPadController:

SubZone1iPadController *sz1 = [[SubZone1iPadController alloc] init...
sz1.delegate = self.delegate;
[self.navigationController pushViewController:...
[sz1 release];

Finally, in the DetailView, make sure the delegate method is implemented. For example:

-(void)SubZone1Tap:(NSString *)name
{
    NSLog(@"SubZone1Tap, name = %@", name);

    //dismiss the popover if that's what you need to do...
    [controladorPopOver dismissPopoverAnimated:YES];
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文