Reputation: 17860
I have a standard table view. Inside each cell UITableViewCell
I have a label. At any given time I need to constantly updating one label for the whole tableView (imagine a clock ticking for example).
In the cellForRowAtIndexPath
I recognize which cell I need to update and assign weak property to the label inside such cell.
Then later, I call
label.text = @"New value";
and expect for that particular cell to refresh that particular label. I checked the weak reference and it's valid and text is changing, however cell is not getting refreshed.
I don't want to call reloadRowsAtIndexPaths
, I just need to refresh one subview inside cell view. Is it possible?
UPDATE:
Here is my code:
This is property definition inside view controller .m file:
@property (nonatomic, weak) UILabel* runningTimerLabel;
I assign this property inside cellForIndex
call:
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
MKSlidingTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"container"];
TimerCell *foregroundCell = [tableView dequeueReusableCellWithIdentifier:kTimerCellId];
UITableViewCell *backgroundCell = [tableView dequeueReusableCellWithIdentifier:@"background"];
BOOL runningCell = (indexPath.row == self.runningTimer);
if (runningCell) {
self.runningTimerLabel = foregroundCell.time;
}
cell.foregroundView = foregroundCell;
cell.drawerView = backgroundCell;
cell.drawerRevealAmount = 146;
cell.forwardInvocationsToForegroundView = YES;
cell.delegate = self;
cell.tag = indexPath.row;
return cell;
}
Here is the method that updates the label:
- (void)refreshRunningTimerCell
{
self.runningTimerLabel.text = @"New text";
}
This method is getting called from a background thread:
- (void)refreshRunningTimer
{
while (1) {
sleep(_sleepTime);
[self performSelectorOnMainThread: @selector(refreshRunningTimerCell)
withObject:nil waitUntilDone: YES];
}
}
Upvotes: 0
Views: 864
Reputation: 108
I really don't understand why you trying to get an reference on UIlabel.
You have self.runningTimer so you have a index row in your tableView, so just get
TimerCell *cell by cellForItemAtIndexPath and just update this cell.
Upvotes: 1
Reputation: 108
I think you can do this:
NSIndexPath *indexPath = [NSIndexPath indexPathForRow:0 inSection:0];
UITableViewCell *cell = [self.tableView cellForItemAtIndexPath:indexPath];
[cell updateLabel:@"New string"];
Upvotes: 1