0

我有我的主视图控制器,点击一个按钮会弹出一个操作表。我想要点击其中的一个选项来显示一个操作表。然而,尽管我进行了所有的搜索,但我似乎无法弄清楚。

我有以下代码:

- (void)actionSheet:(UIActionSheet *)actionSheet clickedButtonAtIndex:(NSInteger)buttonIndex {
    NSString *buttonTitle = [actionSheet buttonTitleAtIndex:buttonIndex];

    if ([buttonTitle isEqualToString:@"Text"]) {
        AddTextViewController *addTextViewController = [self.storyboard instantiateViewControllerWithIdentifier:@"addTextViewController"];        
    }

现在我实例化了视图控制器,我不知道该怎么做。

4

1 回答 1

0

Add this line right after you instantiate it.

if ([buttonTitle isEqualToString:@"Text"]) {
    AddTextViewController *addTextViewController = [self.storyboard instantiateViewControllerWithIdentifier:@"addTextViewController"];        
    [self presentViewController:addTextViewController animated:YES completion:nil];
}

Note

You can also create a custom segue in the Storyboard that presents your view, then instead of instantiating and presenting you can just perform your custom segue. Both work the same.

Storyboard Method

First click your segue in Storyboards, then give it an identifier in the info panel.

Storyboard Segue Settings

Then you can replace your code with this and it should trigger the segue from your Storyboard.

if ([buttonTitle isEqualToString:@"Text"]) {
    [self performSegueWithIdentifier:@"infoSegue" sender:self];
}
于 2013-03-18T14:08:38.727 回答