How to add observer on NSMutableArray?

前端 未结 3 2110
天命终不由人
天命终不由人 2020-12-24 04:44

I have searched a lot but didn\'t find useful code or tutorial.

In my application, I have an mutable array which update in every 60 seconds.

The objects in a

3条回答
  •  爱一瞬间的悲伤
    2020-12-24 04:53

    What is can do is - After updating your Array send a Notification (NSNotificationCenter) and this notification will be received by all the controllers. On receiving the notificaiton the controller should do [tableview reloaddata].

    Code example:

    // Adding an observer
    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(updateTable:) name:@"arrayUpdated" object:nil];
    
    // Post a notification
    [[NSNotificationCenter defaultCenter] postNotificationName:@"arrayUpdated" object:nil]; 
    
    // the void function, specified in the same class where the Notification addObserver method has defined
    - (void)updateTable:(NSNotification *)note { 
        [tableView reloadData]; 
    }
    

提交回复
热议问题