Adding button programmatically to perform segue

前端 未结 1 1199
闹比i
闹比i 2021-01-15 19:53

I am trying to create a button \'on the fly\' using code, and i want that button to perform segue to a different controller. As far as i know, creating segue programmatical

相关标签:
1条回答
  • 2021-01-15 20:15

    In Interface Builder, create a segue. Since you can't connect the segue to the button (it doesn't exist yet), simply connect the segue to the starting ViewController. Then, when you create the button:

    // ....
    [but addTarget:self action:@selector(someMethod) forControlEvents:UIControlEventTouchUpInside];
    // ....
    

    And in the someMethod:

    -(void)someMethod
    {
        [self performSegueWithIdentifier:@"segueIdentifier" sender:self];
    }
    
    0 讨论(0)
提交回复
热议问题