Update value in table cell on iPhone

空扰寡人 提交于 2019-12-03 17:03:15

Thanks for the answers, I found another method though!

By calling this:

NSIndexPath *a = [NSIndexPath indexPathForRow:0 inSection:0]; // I wanted to update this cell specifically
CustomTableViewCell *c = (CustomTableViewCell *)[theTableView cellForRowAtIndexPath:a];

I could then directly modify the label stored in my CustomTableViewCell, like so:

[c nowPlayingTrack].text = ...

Hope this helps someone else one day!

I'm not sure why but just calling reloadData on the tableView was causing run time errors because of the custom label. :(

You can just reload a single row by calling

- (void)reloadRowsAtIndexPaths:(NSArray *)indexPaths withRowAnimation:(UITableViewRowAnimation)animation

For indexPaths you have to make an array that includes the indexPath of the row you want to reload. Row animation just describes whether and how the row should be reloaded, with or without animation:

typedef enum {
   UITableViewRowAnimationFade,
   UITableViewRowAnimationRight,
   UITableViewRowAnimationLeft,
   UITableViewRowAnimationTop,
   UITableViewRowAnimationBottom,
   UITableViewRowAnimationNone,
   UITableViewRowAnimationMiddle
}

If you don't know the indexPath, you can get it by calling

+ (NSIndexPath *)indexPathForRow:(NSUInteger)row inSection:(NSUInteger)section

I assume you're using some type of custom UITableViewCell....

What I normally do is create an array of my custom UITableViewCells, and populate my UITableView from those. This way, I can refresh the underlying object(s) (in this case your UITableViewCell's timer property) and the refresh the UITableView.

You might be able to access it directly (forgive my lack of actual iphone syntax.. it's been several months)

You might be able to access it directly, but I've had problems doing it that way.

[[[myUITableView cells] itemAtIndex:14] setTimerValue:WHATEVER];
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!