Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>You should use <a href="http://developer.apple.com/library/mac/#documentation/Cocoa/Conceptual/KeyValueObserving/KeyValueObserving.html" rel="nofollow">KVO (Key-value observing)</a> to detect when there are changes to your dictionary or array - in this case it seems <code>self.testDict</code>.</p> <p>When you receive this notification, use UITableView's <code>-visibleCells</code> method to update only the visible cells - the others will obviously take on their new value when their cell is recycled using <code>-tableView:cellForRowAtIndexPath:</code>.</p> <p>What's required for KVO: Registering/deregistering when views load/change and setting the variable you wish to observe...</p> <pre><code>- (void)observeValueForKeyPath:(NSString *)keyPath ofObject:(id)object change:(NSDictionary *)change context:(void *)context { if([keyPath isEqual:@"testDict"]) { NSLog(@"KVO change: %@", change); NSArray *visibleCells = [self.myTableView visibleCells]; for(UITableViewCell *cell in visibleCells) { if(/*cell matches the one I'm targeting OR just update regardless*/) // assign value to UILabel } } } // Call this from -viewDidLoad - (void)registerAsObserver { [self addObserver:self forKeyPath:@"testDict" options:NSKeyValueObservingOptionNew context:NULL]; } // Call this from -viewWillDisappear and -viewDidUnload (may not be necessary for -viewDidUnload if already implemented in -viewWillDisappear) - (void)unregisterAsObserver { [self removeObserver:self forKeyPath:@"testDict"]; } </code></pre> <p>Lastly, to update the cell(s) that have changed, call the <code>-reloadRowsAtIndexPaths:withRowAnimation:</code> method to have the underlying system refresh the cell.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload