有没有办法使用操作表导航到另一个视图?
我有一个按钮 - “开始”和一个询问“您要继续吗?”的操作表。并在其中“是”和“取消”
按是时我可以导航到另一个视图吗?
对的,这是可能的。为此viewController
, 表示UIActionSheet
需要采用UIActionSheetDelegate
。使用 Yes 或 Cancel 关闭操作表后,- actionSheet:didDismissWithButtonIndex:
将调用方法,然后您可以从那里导航到另一个视图或忽略它。
编辑:
@interface MyViewController : UIViewController <UIActionSheetDelegate>
-(IBAction)showActionSheet:(id)sender;
@end
@implementation MyViewController
-(IBAction)showActionSheet:(id)sender {
UIActionSheet *actionSheet = [[UIActionSheet alloc] initWithTitle:@"Do you want to procced?" delegate:self cancelButtonTitle:@"Cancel" destructiveButtonTitle:@"YES" otherButtonTitles:nil];
[actionSheet showInView:self.view];
}
-(void) actionSheet: (UIActionSheet *)actionSheet didDismissWithButtonIndex:(NSInteger)buttonIndex {
switch (buttonIndex) {
case 0: {
// for illustration
// let's assume (1) you have a navigation controller
// (2) you are using storyboard
// (3) in the storyboard, you have a viewController with identifier MyChildViewControllerIdentifier
MyChildViewController *mcvc = [self.storyboard instantiateViewControllerWithIdentifier:@"MyChildViewControllerIdentifier"];
[self.navigationController pushViewController:mcvc animated:YES];
break;
}
default:
break;
}
}
PS我没有运行它,如果有任何错误,请告诉我修复它。
关闭操作表,然后[self presentmodalviewcontroller:myview animated:yes]