仅重新加载自定义UITableViewCell的子视图 [英] Reload only a subView of a custom UITableViewCell

查看:94
本文介绍了仅重新加载自定义UITableViewCell的子视图的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我目前正在开发iOS 5及更高版本的应用,其中使用 AVQueuePlayer 的实例在自定义UITableViewCell 中播放视频。

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.

这些自定义单元格中有'n'个播放'n'个视频。

我想实现一个功能,禁用播放器在给定时间后播放视频。

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

我有一个倒数计时器,显示 UILabel 中剩余的时间,用于禁用AVQueuePlayer实例下的播放器。

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

我必须在一分钟后(假设)更新计时器,以显示禁用发生的剩余时间。例如剩下5分钟

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".

我正在使用 NSTimer 来达到此目的。但是,我不知道如何仅重新加载更新自定义UITableViewCell的 UILabel 实例。我在一些线程中看到过使用以下方法

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?

推荐答案

您可以在创建单元格时保存对单元格的引用(听起来好像只是在制作每个单元格中的一个单元格)类型,即使你有一个tableview);或者从桌子上抓住单元格并将标签拉出来。

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.

创建标签(或在接口构建器中设置)时,请调用 [myLabel setTag:LABEL_TAG];

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

然后您可以:

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

在上面的 LABLE_CELL_POSITION 中将是tableview中的单元格(0到...);和 LABEL_TAG 是您要用来表示该视图的任何数字,可能 1234

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.

这篇关于仅重新加载自定义UITableViewCell的子视图的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆