Launch a Uitableview controller from UIbar buttons created dynamically

前端 未结 1 1231
抹茶落季
抹茶落季 2020-12-22 08:23
- (void)createBarButtons
{
    UIBarButtonItem *myCheckButton = [[UIBarButtonItem alloc] initWithTitle:@\"Check Records\" style:UIBarButtonItemStylePlain target:self         


        
相关标签:
1条回答
  • 2020-12-22 09:10

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

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

      embed main scene in nav 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:

      add push segue

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

      destination has navigation bar

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

      give segue storyboard id

    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.

    0 讨论(0)
提交回复
热议问题