UISplitViewControllerDelegate - willHideViewController:...不发送 UIBarButtonItem?

发布于 2024-10-17 08:52:10 字数 1328 浏览 5 评论 0原文

我已经实现了 UISplitViewControllerDelegate,我试图找出为什么我的代码在旋转时崩溃。

现在,我将 AppDelegate 作为实现委托方法的对象,然后为详细视图设置了一个协议 (SubstitutableDetailViewController),以处理 UIBarButton 项的添加/删除。

- (void)splitViewController:(UISplitViewController*)svc 
     willHideViewController:(UIViewController *)aViewController 
          withBarButtonItem:(UIBarButtonItem*)barButtonItem 
       forPopoverController:(UIPopoverController*)pc {

    // Keep references to the popover controller and the popover button, and tell the detail view controller to show the button.

    NSLog(@"barButtonItem class %@",[barButtonItem class]);

    [barButtonItem setTitle:[NSString stringWithString:@"Menu"]];
    self.popoverController = pc;
    self.rootPopoverButtonItem = barButtonItem;

    UIViewController <SubstitutableDetailViewController> *detailViewController = [splitViewController.viewControllers objectAtIndex:1];

    [detailViewController showRootPopoverButtonItem:rootPopoverButtonItem];
}

这里的问题是日志打印出“barButtonItem class __NSCFArray”。

为什么 UIBarButtonItem 会作为数组出现?然后,这会引发错误,因为我正在尝试设置“数组”的标题。

-[__NSCFArray view]: unrecognized selector sent to instance 0x150510

关于为什么它不是正确的对象有什么想法吗?

如果我将它们注释掉,当我尝试将此 barButtonItem 添加到工具栏时,它会引发错误。再次强调,它不是对象的写入类型。

I've implemented the UISplitViewControllerDelegate and I'm trying to find why my code crashes when I rotate.

Right now I have my AppDelegate as the object that implements the delegate methods and then I have a protocol (SubstitutableDetailViewController) setup for my details views to handle the adding/removing of the UIBarButton item.

- (void)splitViewController:(UISplitViewController*)svc 
     willHideViewController:(UIViewController *)aViewController 
          withBarButtonItem:(UIBarButtonItem*)barButtonItem 
       forPopoverController:(UIPopoverController*)pc {

    // Keep references to the popover controller and the popover button, and tell the detail view controller to show the button.

    NSLog(@"barButtonItem class %@",[barButtonItem class]);

    [barButtonItem setTitle:[NSString stringWithString:@"Menu"]];
    self.popoverController = pc;
    self.rootPopoverButtonItem = barButtonItem;

    UIViewController <SubstitutableDetailViewController> *detailViewController = [splitViewController.viewControllers objectAtIndex:1];

    [detailViewController showRootPopoverButtonItem:rootPopoverButtonItem];
}

The issue here is that the log prints out 'barButtonItem class __NSCFArray'.

Why would the UIBarButtonItem be coming through as an array? This then throws an error because I'm trying to set the title of the "array".

-[__NSCFArray view]: unrecognized selector sent to instance 0x150510

Any ideas as to why it wouldn't be the right object?

And if I comment them out, it throws an error when I try to add this barButtonItem to the toolbar. Again, it isn't the write type of object.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

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

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文