0

这就是我到目前为止在我的代码中所拥有的:我正在使用情节提要......

- (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)
  {
    if(buttonIndex == 0)
        [self performSegueWithIdentifier:@"openView" sender:self];
    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];
}
}

/// 我的新代码:

- (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)
{
    if(buttonIndex == 0)
        [self performSegueWithIdentifier:@"openView" sender:self];

}
}

我没有错误,但是当我按下“继续”时,应用程序 force=closes 因为它没有正确连接。我的问题是,我的情节提要中不应该有什么?从具有操作表的视图控制器拖动到我希望“继续”按钮导航到(打开)的视图控制器?这就是我想要发生的事情。谢谢家伙,我对开发很陌生,我正在努力学习。你们帮了很多忙:)

4

1 回答 1

0

您要注意堆栈跟踪的“Receiver () has no segue with identifier 'openView'”行。您正在尝试使用标识符“openView”执行转场,但情节提要中不存在具有该标识符的转场。

打开主故事板并选择连接视图控制器的 segue。选择 Attributes Inspector 并设置 segue 的标识符。

在此处输入图像描述

您还需要删除以下行:

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];

当你执行 segue 时,UIKit 将处理在你的故事板中定义的动画呈现目标视图控制器。你绝对不想尝试多次展示它。

我建议查看 iOS 的 View Controller Programming Guide,特别是“Working with View Controllers in Storyboards”。

于 2013-07-01T02:20:53.923 回答