views:

626

answers:

2

I have a tableView that's loosely based on the DetailViewController in ye olde SQLiteBooks. It's created programatically. Each cell displays a single value that when clicked displays a generic editingController that allows the user to edit that value. Pretty standard Cocoa-touch stuff...

Except...I also have a segmented control in the header of said tableView that depending on it's setting needs to change an attribute (textColor) on a UILabel in ONE of the 8± tableViewCells in the table. I have no IBOutlets for this tableView because I created it entirely in code. So, what do I need to do in my (void)segmentAction:(id)sender method (triggered when segmentedControl changes state) to allow me to access & change this value and display it to the user? When the table was built (cellForRowAtIndexPath) every UILabel was called "value" and then added: [cell.contentView addSubview:value].

I've tried setting a property of the viewController itself that is then checked during cellForRowAtIndexPath and does the textColor business there...and then adding [self.tableView setNeedsDisplay] to my segmentAction: method but it doesn't seem to work?!?

Any ideas?

+1  A: 

If you know the indexpath of the cell you want to modify, you can call cellForRowAtIndexPath: to retrieve the UITableViewCell. Once you have that, you can get the UILabel from it. If you set the UILabel's tag to some useful value when create it, you can then retrieve it from the UITableViewCell via viewWithTag:.

zpasternack
The problem I have with this, or at least my interpretation of this approach, is that I have way too much going on in my cellForRowAtIndexPath involved with getting the table drawn in the first place. Though with come conditional arguments I could probably get this working...
Meltemi
A: 

In the class that implements cellForRowAtIndexPath you could also store a reference to the UILabel that you want when you build the relevant cell.

This would then mean you could alter the label and mark it to be repainted.

Alternately you could hold a local BOOL to show that the cell should be drawn differently - and then use this this in the cellForRowAtIndexPath: to draw it with a background.

You might find this easier with the 3.0 textLabel object in a UITableViewCell

Grouchal
Doh! a simple ivar in my controller that points to said UILabel when it was created! Works great! thx.
Meltemi