Launch a Uitableview controller from UIbar buttons created dynamically

拟墨画扇 提交于 2019-11-29 18:11:12

To launch a new table view controller using storyboards, you want to:

  1. Have your main scene embedded in a navigation controller.

  2. You want to have a push segue from the main controller to the second one. So control-drag from the view controller icon (in the bar below the main scene) to the next scene:

  3. It should then look like (note the appearance of the navigation bar in the destination table view):

  4. Then select the segue and give it a "storyboard identifier":

  5. And now, your code to transition to that scene would look like:

The checkRecordsAction:

- (void)checkRecordsAction
{
    NSLog(@"the new stack action");

    [self performSegueWithIdentifier:@"PushSegue" sender:self];
}

Update:

By the way, in the interest of full disclosure, there's an alternative to the push segue. If you give that next scene, itself, a "storyboard id", you can use the following code (obviously replacing "insertNextScenesStoryboardIdHere" with the identifier you give your next scene:

- (void)checkRecordsAction
{
    NSLog(@"the new stack action");

    UIViewController *controller = [self.storyboard instantiateViewControllerWithIdentifier:@"insertNextScenesStoryboardIdHere"];
    [self.navigationController pushViewController:controller animated:YES];
}

I personally don't like this as much, as your storyboard now has a scene floating out there without any segue, your code now has dictated the nature of the transition between view controllers vs having everything in the storyboard, etc., but it is another approach.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!