0

有没有办法使用操作表导航到另一个视图?

我有一个按钮 - “开始”和一个询问“您要继续吗?”的操作表。并在其中“是”和“取消”

按是时我可以导航到另一个视图吗?

4

2 回答 2

3

对的,这是可能的。为此viewController, 表示UIActionSheet需要采用UIActionSheetDelegate。使用 Yes 或 Cancel 关闭操作表后,- actionSheet:didDismissWithButtonIndex:将调用方法,然后您可以从那里导航到另一个视图或忽略它。

参考资料:http: //developer.apple.com/library/ios/#documentation/uikit/reference/UIActionSheet_Class/Reference/Reference.html#//apple_ref/occ/cl/UIActionSheet

http://developer.apple.com/library/ios/#documentation/uikit/reference/UIModalViewDelegate_Protocol/UIActionSheetDelegate/UIActionSheetDelegate.html


编辑:

@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我没有运行它,如果有任何错误,请告诉我修复它。

于 2012-04-05T16:42:23.153 回答
1

关闭操作表,然后[self presentmodalviewcontroller:myview animated:yes]

于 2012-04-05T16:41:05.663 回答