iPhone:NSLog self.window.rootviewcontroller

时间:2012-12-12 13:38:34

标签: xcode nslog uiapplicationdelegate

我需要知道我的winow.rootviewcontroller名称。

例如

    UITabBarController *demoTabBarController = [[UITabBarController alloc] init];
    [self.demoTabBarController setDelegate:self];
    self.demoTabBarController.viewControllers = [NSArray arrayWithObjects:mainNavController, searchView, challengeView, nil];
    self.window.rootViewController = self.demoTabBarController;

所以在NSLog中我想要demoTabBarController作为结果。有什么办法可以实现吗?

请注意,我不想要rootviewcontroller的类名。

2 个答案:

答案 0 :(得分:0)

demoTabBarController只是指向UITabBarController的指针的名称。它实际上并没有存储在内存中。

您可以使用[self.window.rootViewController className]获取类名,但这应该返回UITabBarController

答案 1 :(得分:0)

不直接。指针变量不保存有关其他指针变量赋予对象引用的任何信息。如果您需要某种关于对象历史记录的标识信息,则必须子类化UITabBarController并保存要在自定义类中显示的内容。

(如果你描述为什么你认为这是有用的,有人可能有另一种方法来解决更基本的问题。)