开发者

refresh uitableview data

how can I refresh the content of 开发者_如何学PythonUITableView every 5 minutes?


Checkout NSTimer and UITableViews reloadData.

Assuming that the view of the current controller is a UITableView, and that you have declared a NSTimer called timer in your controller, the following code should do the trick:

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

   [super viewDidLoad];
}

UPDATE:

Someone else has proposed the use timerWithTimeInterval:target:selector:userInfo:repeats: which is basically the same as the scheduledTimerWithTimeInterval that I have used in my example.

They differ, though, in that scheduledTimerWithTimeInterval adds the timer to the current run loop, whilst with the timerWithTimerInterval method, you will need to add the timer to a run loop your self.


create an NSTimer that calls a method 'foo' every 5 mins (in seconds), then in 'foo' just write

[self.tableView reloadData];


Put an NSTimer in and shoot it off every 300 seconds to refresh table view?

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜