iOS:@synchronized阻止无效

时间:2017-05-31 03:41:29

标签: ios objective-c iphone uistoryboardsegue

我试图避免这次崩溃:

*** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: 'Receiver (<myNewViewController: 0x7ff3c5209330>) has no segue with identifier 'myNewViewController''

使用@synchronized。这是我的实施:

ViewController.m:

- (void)viewDidLoad {
    [super viewDidLoad];
    self.canLoadViewController = YES;
}

-(void)viewDidAppear:(BOOL)animated
{
    [super viewDidAppear:animated];
    NSLog(self.canLoadViewController ? @"Yes" : @"No");
    @synchronized(self) {
        if (self.canLoadViewController == YES) {
            [self performSegueWithIdentifier:@"myNewViewController" sender:self];
        }
    }
}

-(void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
{
    if ([segue.identifier isEqualToString:@"myNewViewController"]){
       self.canLoadViewController = NO;
        myNewViewController *vc = (myNewViewController*)[segue destinationViewController];
        vc.title = @"azul";
    }
}

问题是viewDidAppear被调用了两次,self.canLoadViewController的值与prepareForSegue中设置的值不同。

你们中的任何人都知道为什么@synchronized不起作用?或者我做错了什么?

我非常感谢你的帮助。

0 个答案:

没有答案