动作表导航

时间:2013-06-24 04:33:13

标签: xcode uistoryboard uiactionsheet

这是我目前在我的代码中所拥有的: 我正在使用故事板......

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

}
}

我没有错误但是当我按下“继续”时,app force =关闭,因为它没有正确连接。我的问题是,我应该在故事板上怎么说?从具有动作表的viewcontroller拖动到我希望“继续”按钮导航到(打开)的viewcontroller?这就是我想要发生的事情。谢谢你我很擅长开发,我正在努力学习。你们帮助很多:)

1 个答案:

答案 0 :(得分:0)

您要注意“Receiver()没有带有标识符'openView'”堆栈跟踪行的segue。您正尝试使用标识符“openView”执行segue,但故事板中不存在带有该标识符的segue。

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

enter image description here

您还需要删除以下行:

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将处理使用您在故事板中定义的动画呈现目标视图控制器。你绝对不想尝试多次呈现它。

我建议您查看View Controller Programming Guide for iOS,特别是“使用故事板中的视图控制器”。