iphone - 刷新uitableview数据

标签 iphone objective-c uitableview

如何每5分钟刷新一次UITableView的内容?

最佳答案

结账 NSTimer和 UITableViews reloadData。

假设当前 Controller 的 View 是 UITableView,并且您已在 Controller 中声明了一个名为计时器的 NSTimer,则以下代码应该可以解决问题:

- (void)viewDidLoad {
   timer = [NSTimer scheduledTimerWithTimeInterval:300.0 
                                            target:[self view] 
                                          selector:@selector(reloadData) 
                                          userInfo:nil 
                                           repeats:YES];

   [super viewDidLoad];
}

更新:

其他人建议使用 timerWithTimeInterval:target:selector:userInfo:repeats: ,它与我在示例中使用的 scheduledTimerWithTimeInterval 基本相同。

不过,它们的不同之处在于,scheduledTimerWithTimeInterval 将计时器添加到当前运行循环,而使用timerWithTimerInterval 方法,您需要将计时器添加到您自己的运行循环。

关于iphone - 刷新uitableview数据,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3249016/

相关文章:

php - 如何通过 php 通知我的 iPhone 应用程序名称已添加到数据库中?

objective-c - 在源列表中显示固定和可编辑的项目

ios - 获取主视图 Controller 中子容器 View 中 tableView 的引用

ios - 如何让 reloadData 在 UITableView 上工作

iphone - setHttpMethod 奇怪的行为

css - 响应移动和显示 : none - Wordpress - Visual Composer

iphone - Windows Phone 以编程方式连接两个设备并镜像屏幕

ios - 当应用程序后台运行然后恢复时,带有 HTML5 数据库的 UIWebView 不会加载

objective-c - Xcode for How to call function from one class to another class function in iPhone Apps

ios - UITableView - 辞去外部触摸的第一响应者