【问题标题】:Navigating to UITableViewController embedded with UINavigationController导航到嵌入了 UINavigationController 的 UITableViewController
【发布时间】:2017-02-22 23:11:42
【问题描述】:

我正在尝试以编程方式呈现UITableViewController 和嵌入其中的UINavigationController。但是,它会在没有导航控制器的情况下显示。我该如何解决这个问题?

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {

MyTableViewController *myt = [self.window.rootViewController.storyboard instantiateViewControllerWithIdentifier:@"mytableviewControllerID"];
         UINavigationController *nav = ((UINavigationController*)myt);

        self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];

        self.window.rootViewController = nav;
        [self.window makeKeyAndVisible];

return YES;

}

【问题讨论】:

    标签: ios objective-c iphone uinavigationcontroller appdelegate


    【解决方案1】:

    你做错了

     UINavigationController *nav = ((UINavigationController*)myt);
    

    这不会将您的控制器嵌入到导航控制器中。您只是将控制器转换为导航控制器。

    试试这个:

    - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
    
    MyTableViewController *myt = [self.window.rootViewController.storyboard instantiateViewControllerWithIdentifier:@"mytableviewControllerID"];
    UINavigationController *nav = [[UINavigationController alloc]initWithRootViewController:myt];
    
    self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
    self.window.rootViewController = nav;
    [self.window makeKeyAndVisible];
    
    return YES;
    
    }
    

    【讨论】:

      猜你喜欢
      • 2017-04-08
      • 1970-01-01
      • 2015-05-15
      • 1970-01-01
      • 2016-11-20
      • 2019-03-03
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多