Performing segue from another class

前端 未结 3 793
南方客
南方客 2021-01-16 11:12

I am trying to call performSegueWithIdentifier from different class which is NSObject class and I am receiving this error:

Terminating app due to uncaught exception

3条回答
  •  悲&欢浪女
    2021-01-16 11:17

    I was having the same issue and I managed to resolve it by using NSNotificationCenter.

    In the NSObject class .m file I added:

    [[NSNotificationCenter defaultCenter] postNotificationName:@"performsegue"
                                                        object:nil];
    

    In the ViewController class .m file -

    1.In the -(void) viewDidLoad I added:

     [[NSNotificationCenter defaultCenter] addObserver:self
                                             selector:@selector(performsegueNotification:)
                                                 name:@"performsegue"
                                               object:nil];
    

    2.In the -(void) viewDidUnload I added:

    [[NSNotificationCenter defaultCenter] removeObserver:self];
    

    3.Created the method performsegueNotification:

    -(void)performsegueNotification:(NSNotification *) notif
    {
    
        [self performSegueWithIdentifier: @"PresentView" sender:self];
    
    }
    

提交回复
热议问题