prepareForSegue未被调用

时间:2017-06-02 15:02:25

标签: ios objective-c iphone

我创建了三个场景,每个场景都有一个按钮和一个标签,如图1所示。 Scene1链接到Scene2到#34; Show Segue,名为scene1To2" ,Scene2链接到scene3到#34; Show Segue叫做scene2To3"最后,Scene3链接到scene1到#34; Show Segue,名为scene3To1"。

我想打电话给#34; prepareForSegue"当单击scene1中的按钮时,我编写了下面的code1部分中显示的代码..

但是当我运行代码时,NSLog消息" NSLog(@"从scene1To2&#34转移;);"没有出现

请让我知道为什么NSLog消息没有显示

CODE1

@interface ViewController ()

@end

@implementation ViewController

 - (void)viewDidLoad {
 [super viewDidLoad];
 // Do any additional setup after loading the view, typically from a  
 //nib.
 }

 - (void)didReceiveMemoryWarning {
  [super didReceiveMemoryWarning];
 // Dispose of any resources that can be recreated.
}

- (IBAction)from1To2:(id)sender {
   NSLog(@"Hi");

   [self performSegueWithIdentifier:@"scene1To2" sender:self];
 }

 -(void)prepareForSegue:(UIStoryboardSegue *)segue
 {
    if ([segue.identifier isEqualToString:@"scene1To2"])
    {
        NSLog(@"transiting from scene1To2");
    }

  }

  @end

3 个答案:

答案 0 :(得分:1)

您的方法签名错误。看看这是否有效:

- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    if ([segue.identifier isEqualToString:@"scene1To2"])
    {
        NSLog(@"transiting from scene1To2");
    }
}

答案 1 :(得分:0)

在故事板上的Segue链接中,您是否已将segue名称添加到segue标识符中?

答案 2 :(得分:-1)

您可以使用类似的东西,导入scene1To2控制器。

scene1To2 *view = [[UIStoryboard storyboardWithName:@"YOUR_STORYBOARD" bundle:nil] instantiateViewControllerWithIdentifier:@"scene1To2"];
[self presentViewController:view animated:YES completion:nil];

然后你去另一个视图控制器