gpt4 book ai didi

iphone - 无论我做什么,ParentViewController 都是 nil

转载 作者:太空狗 更新时间:2023-10-30 03:55:02 24 4
gpt4 key购买 nike

我的 Controller 层次结构:

  • TabBaseController (UITabBarController)
    • 子类 Controller

在我的 tabbasecontroller 中,我有一个导航栏按钮,它将使用 presentModalViewController 方法的子类 Controller 翻转到第二个 UITabBarController。

所以我的问题是:为什么不

self.parentViewController

在第二个 UITabBarController 中工作?为零。

我在第二个 UITabBarController 的 viewDidLoad 方法中尝试这样做:

if (self.parentViewController == nil) {
NSLog(@"Parent is nil");
}

已更新

这是 UITabBarController 中的方法,带有呈现它的 navigationItemButton

-(IBAction)openModalTabController:(id)sender {  

if (self.nvc == nil) {
ModalTabController *vc = [[ModalTabController alloc] init];
self.nvc = vc;
[vc release];
}

[self presentModalViewController:self.nvc animated:YES];
}

这是我模态呈现的 Controller (UITabBarController):

标题:

@interface NewBuildingViewController : UITabBarController {
}
@end

主要内容:

@implementation NewBuildingViewController

- (id)init {
[super initWithNibName:nil bundle:nil];

ViewController1 *vc1 = [[ViewController1 alloc] init];
ViewController2 *vc2 = [[ViewController2 alloc] init];
ViewController3 *vc3 = [[ViewController3 alloc] init];

NSArray *controllers = [[NSArray alloc] initWithObjects:vc1, vc2, vc3, nil];

[vc1 release];
[vc2 release];
[vc3 release];

self.viewControllers = controllers;
[controllers release];

self.modalTransitionStyle = UIModalTransitionStyleFlipHorizontal;

return self;
}

- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil {
return [self init];
}

@end

我还想补充一下,翻转时控制台会显示此消息(警告):

使用两阶段旋转动画。要使用更流畅的单阶段动画,此应用程序必须删除两阶段方法实现。当旋转多个 View Controller 或 View Controller 不是窗口委托(delegate)时,不支持使用两阶段旋转动画

最佳答案

如果您要展示如何呈现第二个 UITabBarController,将会很有帮助。您是否可能忽略了 UITabBarController 类引用中的以下警告?

When deploying a tab bar interface, you must install this view as the root of your window. Unlike other view controllers, a tab bar interface should never be installed as a child of another view controller.

关于iphone - 无论我做什么,ParentViewController 都是 nil,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4639438/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com