views:

488

answers:

3

The UITableViewCell is usually drawn with the UITableViewDelegate or UITableViewDataSource protocol methods, like

-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath

But how would I change the cell outside of these methods? If I wanted to, for instance, turn a UITableViewCell's textLabel color to red using a button on the same screen, how would I refer to that cell and change it?

+1  A: 

If I'm understanding your question correctly, assuming you know the row index of the cell you want to change you could simply have your button use the method:

- (UITableViewCell *)cellForRowAtIndexPath:(NSIndexPath *)indexPath

... to get a the UITableViewCell you want to edit and then use that pointer to change the cells textColor property etc.

UITableViewCell *firstCell = [someTableView cellForRowAtIndexPath:0];
firstCell.textColor = [UIColor redColor];
tmh
A: 

Can you access the button from the tableView:cellForRowAtIndexPath: method? If so, you can use an NSNotificationCenter to post notifications when the button is pressed and listen for those notifications from the table view cell (which you'll have to subclass).

Jeff Kelley
+1  A: 

Easiest way is probably to have a variable that stores what color you want the row to be.

When you press the button, change the variable to the new color, then call [tableview reloadData]

Nathaniel Martin