1

I am currently developing an app for iOS 5 and above in which a video is played inside a custom UITableViewCell using an instance of AVQueuePlayer.

There are 'n' number of such custom cells playing 'n' number of videos.

I want to implement a functionality which disables the player from playing the video after a given time.

I have a countdown timer which displays the time left in a UILabel for disabling the player beneath the instance of AVQueuePlayer.

I have to update the timer after a minute(suppose) to show the time left for the disabling to take place. e.g. "5 mins left".

I am using NSTimer for this purpose. But, I dont know how to only reload or update the UILabel instance of the custom UITableViewCell. I have seen in some threads the use of the following method

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

But, if I do so when the video is playing, it stops and gets reloaded again.

Is there a better solution to this issue?

An1Ba7
  • 355
  • 11
  • 25

1 Answers1

3

You could either save a reference to your cell when you create it (sounds like you're only making one of each cell type, even though you have a tableview); or grab the cell from the table and pull the label out of it.

I'd be tempted to set the tag of the label, then use that to get the label back.

When you create the label (or set it in interface-builder) call [myLabel setTag:LABEL_TAG];

Then later you can:

UITableViewCell * myCell = self.myTableView cellForRowAtIndexPath:LABLE_CELL_POSITION];
UILabel * myLabel = [cell viewWithTag:LABEL_TAG];
myLabel.setText:@"my new value";

In the above LABLE_CELL_POSITION would be position of the cell in your tableview (0 to ...); and LABEL_TAG is any number you want to use to denote that view, maybe 1234.

CarlJ
  • 9,461
  • 3
  • 33
  • 47
Dave
  • 7,552
  • 4
  • 22
  • 26
  • But cellForRowAtIndexPath takes an object of NSIndexPath as an argument. Should I save the IndexPath object and then pass this on for this method to get the UITableViewCell? – An1Ba7 Jan 29 '13 at 05:13
  • 1
    Ah, then just build an index path. You could replace LABEL_CELL_POSITION with [NSIndexPath indexPathForRow:LABEL_CELL_POSITION inSection:0]. Your goal is to get your UILabel. So, use the above to get the cell, then ask the cell for the label (via viewWithTag or similar). If you build your table the same way, you may not need to "save" the index path. You'll know the cell you want is 0 (or 1, or 2...). – Dave Jan 29 '13 at 05:29