How to use NSNotification

后端 未结 2 964
再見小時候
再見小時候 2020-12-18 04:51

In my application there is two viewControllers as FirstViewController and DetailViewController. When tap on a table cell, it navigate to Det

相关标签:
2条回答
  • 2020-12-18 05:31

    post the notification from detailViewController and add firstViewController as the observer.

    Make sure you remove fireViewController from the observer list from viewDidUnload.

    Right now you are adding detailViewController as observer.

    0 讨论(0)
  • 2020-12-18 05:36
    -(void)viewDidLoad {
    
    [NSNotificationCenter defaultCenter];
    NSNotification* notification = [NSNotification notificationWithName:@"MyNotification" object:self];
    [[NSNotificationCenter defaultCenter] postNotification:notification];  
    
    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector (objFirstViewController) name:@"MyNotification" object:nil];
    
    }
    
    
    -(IBAction) save{
    
    [[NSNotificationCenter defaultCenter] postNotificationName:MyNotification object:sender];
    
    //this will go to where you implement your selector objFirstViewController.
    
    }
    
    -(void)objFirstViewController:(NSNotification *)notification {
    
    }
    
    0 讨论(0)
提交回复
热议问题