[英]How do I present a modal view upon an option in UIActionSheet being tapped?
I have my main view controller, and tapping a button brings up an action sheet. 我有主视图控制器,点击按钮会弹出一个动作表。 I want one of the options tapped there to bring up an action sheet.
我希望其中一个选项可以调出操作表。 I can't seem to figure it out, however, despite all my searching.
尽管进行了所有搜索,但我似乎无法弄清楚。
I have the following code: 我有以下代码:
- (void)actionSheet:(UIActionSheet *)actionSheet clickedButtonAtIndex:(NSInteger)buttonIndex {
NSString *buttonTitle = [actionSheet buttonTitleAtIndex:buttonIndex];
if ([buttonTitle isEqualToString:@"Text"]) {
AddTextViewController *addTextViewController = [self.storyboard instantiateViewControllerWithIdentifier:@"addTextViewController"];
}
Now that I instantiated the view controller, I don't know what to do. 现在,我实例化了视图控制器,我不知道该怎么办。
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. 首先在情节提要中单击您的序列,然后在信息面板中为其指定标识符。
Then you can replace your code with this and it should trigger the segue from your Storyboard. 然后,您可以用此代码替换代码,它应该触发情节提要中的segue。
if ([buttonTitle isEqualToString:@"Text"]) {
[self performSegueWithIdentifier:@"infoSegue" sender:self];
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.