Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6660521
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T02:09:56+00:00 2026-05-26T02:09:56+00:00

I have a custom UITableViewCell which is displaying various attributes of a Person object

  • 0

I have a custom UITableViewCell which is displaying various attributes of a Person object (backed by Core Data) … some labels, images etc. I currently force the whole tableview to reload whenever any property changes, and that’s obviously not efficient. I know with KVO, I should be able to add a listener to a label in the cell that can listen for changes in the Person’s properties. But I’m not sure how to implement it and can’t find any examples.

Here’s what I typically do in my UITableView’s cellForRowAtIndexPath:

    - (UITableViewCell *) tableView: (UITableView *) tableView cellForRowAtIndexPath: (NSIndexPath *) indexPath
    {
        static NSString *simple = @"CustomCellId";

        CustomCell *cell = (CustomCell *) [tableView dequeueReusableCellWithIdentifier:simple];

        if (cell == nil)
        {
            NSArray *nib =  [[NSBundle mainBundle] loadNibNamed:@"CustomCell" owner:self options:nil];

            for (id findCell in nib )
            {
                if ( [findCell isKindOfClass: [CustomCell class]])
                {
                    cell = findCell;
                }    
            }
         }
         Person *managedObject = [self.someArray objectAtIndex: indexPath.row];
         cell.namelabel.text =  managedObject.displayName;
         return cell;
}

The cell is hooked up in IB. I would want to detect when displayName changes, and update just the name label.
Thanks

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-26T02:09:57+00:00Added an answer on May 26, 2026 at 2:09 am

    For background, you probably want to read the Key-Value Observing and Key-Value Coding Guides, if you haven’t already. Then review the NSKeyValueObserving category methods.

    http://developer.apple.com/library/mac/#documentation/Cocoa/Reference/Foundation/Protocols/NSKeyValueObserving_Protocol/Reference/Reference.html

    In a nutshell, you need to carefully manage adding and removing the observing object to the observed objects list of observers (pardon the seeming redundancy of that statement). You don’t want to have an object going away with observers still registered, or you get complaints and possible other issues.

    That said, you use -addObserver:keyPath:options:context to add an object as an observer. Context should be a statically declared string. The options argument controls what data you get back in your observation method (see below). The keyPath is the path of property names from the observed object to the observed property (this may traverse multiple objects, and will be updated when intermediate objects change, not just when the leaf property changes).

    In your case, you could observe the label, and use the text keyPath, or the cell, and use the nameLabel.text key path. If the table view class were designed differently, you might observe the entire array of cells, but there is no such property on UITableView. The problem with observing the cell is that the table view might delete it at any time (if your design uses multiple cells that serve the same purpose in a variable-length list). If you know your cells are static, you can probably observe them without worry.

    Once you have an observer registered, that observer must implement
    -observeValueForKeyPath:ofObject:change:context:, confirm that the context matches (just compare the pointer value to your static string’s address; otherwise, invoke super’s implementation), then look into the change dictionary for the data you want (or just ask the object for it directly) and use it to update your model as you see fit.

    There are many examples of KVO in sample code, including on Apple’s developer site, and as part of the bindings samples on Malcolm Crawford (mmalc)’s site, but most of it is for Mac OS X, not iOS.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a custom UITableViewCell which has some subviews. i.e. some labels, some images.
I have a custom UITableViewCell which has an image & and some text. When
I have a custom-subclassed UITableViewCell which will include a few labels, to which I
I have a custom UITableViewCell which contains several UIButtons. Each button's frame position is
I have a UISwitch inside a custom UITableViewCell (the subclass of which I call
I have a custom UITableViewCell which acts as a check list. As the user
I have a custom UITableViewCell which I created in Interface Builder. I am successfully
I have a custom UITableViewCell which is part of a navigation controller. The cell
I have a custom UITableViewCell that contains a UISlider control and a UILabel which
I have a custom UITableViewCell which fills the cell with a background PNG and

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.