ios - UINavigationController pushViewController 不起作用

标签 ios iphone objective-c uiviewcontroller uinavigationcontroller

我查看了所有其他类似问题,但找不到解决方案。

我的 iPad Storyboard有一个标签栏 Controller 作为“初始 View Controller ”,它通过“关系顺序 View Controller ”链接到导航 Controller ,导航 Controller 通过“ Root View ”链接链接到 View Controller A,它有一个 UIButton,它通过“手动序列推送”链接到 View Controller B。

Tab Bar Cntrl => Navigation Cntrlr ==(root view)==> View Cntrl A, UIButton ==(push)==> View Cntrl B

因此,在运行时,在显示 View Controller A 的情况下,按下其 UIButton 需要更改为 View Controller B。但是没有任何反应................................

响应 UIBUTTON 的代表(按住手势)............

 - (void)schedule_long_press_delegate:(UILongPressGestureRecognizer *)recognizer { if (recognizer.state == UIGestureRecognizerStateEnded) { printf("Long press Ended ................. \n");
    // Get storyboard:
    UIStoryboard *mainStoryboard = [UIStoryboard storyboardWithName:@"MainStoryboard_iPad"
                                                             bundle: nil];
    printf("mainStoryboard = %x \n", (int)mainStoryboard ); // !!! ax

    // Get nav controller for MANAGE view:
    UINavigationController *MANAGE_UINavigationController = (UINavigationController*)[mainStoryboard 
                        instantiateViewControllerWithIdentifier: @"MANAGE_Storyboard_ID"];
    printf("MANAGE_UINavigationController = %x  \n", (int)MANAGE_UINavigationController ); // !!! ax


    // Get MANAGE view's view controller:
    SCHEDULE_UIViewController *schedule_UIViewController = [self.storyboard instantiateViewControllerWithIdentifier:
                                        NSStringFromClass([SCHEDULE_UIViewController class])];
    printf("schedule_UIViewController = %x  \n", (int)schedule_UIViewController ); // !!! ax

    // Change screen to MANAGE view:
    [MANAGE_UINavigationController  pushViewController: schedule_UIViewController animated:YES];
}
else {
    printf("Long press detected .....................   \n");
}        

}

Storyboard设置:

UITabBarController ... Storyboard ID is blank. ..links to: UINavigationController ... Class=UINavigationController StoryboardID = "MANAGE_Storyboard_ID" ..links to: UIViewController ... Class=acc StoryboardID is blank (INITIAL VIEW) ..links to: UIViewController ... Class & StoryboardID = "SCHEDULE_UIViewController" (TARGET VIEW)

输出:……

当委托(delegate)触发时,它会显示已全部设置的指针:

mainStoryboard = 1f8b4900
 MANAGE_UINavigationController = 1e5d45f0
 schedule_UIViewController 2 = 1e5d4b20 

我是否缺少一些初始化?

最佳答案

“实例化”一词告诉您正在创建一个实例。因此,当您调用时:

UINavigationController *MANAGE_UINavigationController = (UINavigationController*)[mainStoryboard instantiateViewControllerWithIdentifier: @"MANAGE_Storyboard_ID"];

您正在创建一个导航 Controller ,该 Controller 当前不属于可见层次结构。

尽管您的对象和调用可能没问题,但您并未与管理屏幕的 Controller 进行交互。

(注意:如果您使用符合 Apple 标准的代码风格,其他人会更容易分析您编写的内容。)

关于ios - UINavigationController pushViewController 不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22883688/

相关文章:

objective-c - 如何在 NSView 中嵌入视频播放器?

iphone - 为什么无法在 uiwebview 中打开 .docx 文件

iOS7 : What is the best way to give the user the ability to choose between taking a photo and going to a photo gallery?

iOS UITableView 自动调整单元格大小并带有部分索引

ios - 释放分配属性(property)

ios - 从 imagePicker 选择图像时,iOS11.2.6、Xcode 9.2 应用程序崩溃

ios - 如何为带有部分的表格 View 单元格设置备用背景颜色

ios - 如何在 iOS 上使用 PhoneGap 从照片库中获取图片?

iphone - UIView 调整 subview 大小

iphone - objc_msgSend() 错误消息,为什么?