Yolanda
Yolanda

Reputation: 263

refresh uitableview data

how can I refresh the content of UITableView every 5 minutes?

Upvotes: 2

Views: 2454

Answers (3)

Vegar
Vegar

Reputation: 12898

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.

Upvotes: 4

jmont
jmont

Reputation: 423

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

[self.tableView reloadData];

Upvotes: 2

Louie
Louie

Reputation: 5940

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

Upvotes: 0

Related Questions