在 PopOverController 中使用 NavController 时出现 SIGABRT 错误

发布于 2025-01-03 08:46:40 字数 2063 浏览 2 评论 0原文

我之前发布过类似的问题,但这次我提供一些代码进行分析。我正在 AppDelegate.m 文件中创建 PopOverController,并添加一个 NavigationController 变量,我想将其传递给 PopOverController.m 文件,以便使用它来推送其他视图。以下是我在 AppDelegate.m 中创建 PopOver 的方法

- (void)tabBarController:(UITabBarController *)tabBarController didSelectViewController:(UIViewController *)viewController
{
    if([viewController isKindOfClass:[SecondViewController class]]){
        NSInteger index = [[self tabBarController] selectedIndex];
        CGRect buttonFrame = [[[[[self tabBarController] tabBar] subviews] objectAtIndex:index+1] frame];

        PopOverViewController *popoverContentController = [[PopOverViewController alloc]init];

        UINavigationController *navcon = [[UINavigationController alloc]initWithRootViewController:popoverContentController];

        popoverContentController.contentSizeForViewInPopover = CGSizeMake(250, 85);
        popover = [[UIPopoverController alloc]initWithContentViewController:popoverContentController];            

        NSLog(@"X:%f Y:%f",buttonFrame.origin.x,buttonFrame.origin.y);

        [popover presentPopoverFromRect:buttonFrame inView:self.tabBarController.tabBar permittedArrowDirections:UIPopoverArrowDirectionDown animated:YES];

    }
}

,在 PopOverController.m 中,我尝试使用 NavigationController 来选择如下视图:

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
    sendFeedback *sendEmailViewController = [[sendFeedback alloc]initWithNibName:@"sendFeedback" bundle:nil];
    downLoad *downloadFilelViewController = [[downLoad alloc]initWithNibName:@"downLoad" bundle:nil];

    if (indexPath.row == 0)
        [self.navigationController pushViewController:sendEmailViewController animated:YES];
   else
       [self.navigationController pushViewController:downloadFilelViewController animated:YES];
}

但是当我单击 PopOver 的 TabBar 项时,我收到此 SIGABRT 消息:

由于未捕获的异常“NSGenericException”而终止应用程序,原因:“内容视图控制器参数必须是其关联视图控制器层次结构的根。”

出现这种情况有什么原因吗?我的代码中有什么地方犯了错误吗?

I have posted similar question previously, but this time I am providing some code for analysis. I am creating PopOverController in my AppDelegate.m file and I am adding a NavigationController variable which I want to pass to PopOverController.m file so that using that I want to push other views. Here is how I am creating the PopOver in AppDelegate.m

- (void)tabBarController:(UITabBarController *)tabBarController didSelectViewController:(UIViewController *)viewController
{
    if([viewController isKindOfClass:[SecondViewController class]]){
        NSInteger index = [[self tabBarController] selectedIndex];
        CGRect buttonFrame = [[[[[self tabBarController] tabBar] subviews] objectAtIndex:index+1] frame];

        PopOverViewController *popoverContentController = [[PopOverViewController alloc]init];

        UINavigationController *navcon = [[UINavigationController alloc]initWithRootViewController:popoverContentController];

        popoverContentController.contentSizeForViewInPopover = CGSizeMake(250, 85);
        popover = [[UIPopoverController alloc]initWithContentViewController:popoverContentController];            

        NSLog(@"X:%f Y:%f",buttonFrame.origin.x,buttonFrame.origin.y);

        [popover presentPopoverFromRect:buttonFrame inView:self.tabBarController.tabBar permittedArrowDirections:UIPopoverArrowDirectionDown animated:YES];

    }
}

And in my PopOverController.m I am trying to use the NavigationController to choose views like this:

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
    sendFeedback *sendEmailViewController = [[sendFeedback alloc]initWithNibName:@"sendFeedback" bundle:nil];
    downLoad *downloadFilelViewController = [[downLoad alloc]initWithNibName:@"downLoad" bundle:nil];

    if (indexPath.row == 0)
        [self.navigationController pushViewController:sendEmailViewController animated:YES];
   else
       [self.navigationController pushViewController:downloadFilelViewController animated:YES];
}

But when I click on my TabBar item for the PopOver I am getting this SIGABRT message :

Terminating app due to uncaught exception 'NSGenericException', reason: 'The content view controller argument must be the root of its associated view controller hierarchy.'

Any reason why this is appearing? Is there somewhere I am making a mistake in my code ?

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

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

发布评论

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

评论(1

顾北清歌寒 2025-01-10 08:46:40
UINavigationController *navcon = [[UINavigationController alloc] initWithRootViewController:popoverContentController];

您正在尝试将弹出控制器放入导航控制器中。我认为你不想要这个。

要将导航放在弹出窗口中,您应该执行此操作,

UINavigationController *navcon = [[UINavigationController alloc] initWithRootViewController:myViewController];
popoverContentController = [UIPopoverController initWithContentViewController:navcon]

并使用所需的 viewController(例如 TableViewController 或其他东西)初始化导航控制器。

UINavigationController *navcon = [[UINavigationController alloc] initWithRootViewController:popoverContentController];

you are trying to put a popover controller in a navigation controller. I don't think you want this.

To put navigation in popover, you should do this,

UINavigationController *navcon = [[UINavigationController alloc] initWithRootViewController:myViewController];
popoverContentController = [UIPopoverController initWithContentViewController:navcon]

and init the navigation controller with the viewController you want, like TableViewController or something else.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文