Make Actionsheet按钮打开另一个ViewController?

时间:2013-02-25 04:31:40

标签: xcode ios6

有人给了我这个代码,是不是正确?如果是这样我怎么用呢?我是一个菜鸟,所以你能用更简单的术语解释一下吗?谢谢你们:)

- (IBAction)OpenActionSheetButton:(id)sender {


UIActionSheet *actionsheet = [[UIActionSheet alloc]initWithTitle:@"There is no going back,
 are you sure???" delegate:self cancelButtonTitle:@"Cancel"
 destructiveButtonTitle:@"Continue" otherButtonTitles:nil, nil];
[actionsheet showInView:self.view];}

-(void)actionSheet:(UIActionSheet *)actionSheet clickedButtonAtIndex:
(NSInteger)buttonIndex
{
if(buttonIndex == 0)
{
UIViewController *controller =  [self.storyboard 
instantiateViewControllerWithIdentifier:@"storyboardViewIdentifier"];
    //storyboardViewIdentifier is the ViewController identifier you specify in the
storyboard

    //PUSH
    [self.navigationController pushViewController:controller animated:YES];
    //Modal
    [self presentViewController:controller animated:YES completion:Nil];
}

}

1 个答案:

答案 0 :(得分:0)

我不确定故事板的情况,但是对于XIB的情况,我需要将UINavigationController对象设置为rootviewcontroller,以便我可以从一个viewcontroller推送到另一个,我认为在storyboard中它可能是相同的如果是这样,请参阅这些答案,firstsecond将导航控制器设置为故事板环境中的rootviewcontroller。