如何每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/