I have a tableview. I need to add cells of the tableview at a particular interval of time after loading so that we can view loading the cells.How can i do this. Any idea will be greatly appreciated!
+1
A:
Set up a timer in your viewDidLoad method of your UITableViewController like so:
- (void)viewDidLoad {
[super viewDidLoad];
// Schedule a timer to fire every 5 seconds and call our
// insertNewObject method
NSTimer *timer = [NSTimer scheduledTimerWithTimeInterval:5
target:self
selector:@selector(insertNewObject)
userInfo:nil
repeats:YES];
}
Then insert a new row into our data source and tell the tableView about it
- (void)insertRow {
// dataSource defined elsewhere
[dataSource addObject:@"New row"];
NSIndexPath *indexPath = [NSIndexPath indexPathForRow:([dataSource count] - 1) inSection:0];
NSArray *indexPaths = [NSArray arrayWithObject:indexPath];
[[self tableView] beginUpdates];
[[self tableView] insertRowsAtIndexPaths:indexPaths withRowAnimation:UITableViewRowAnimationFade];
[[self tableView] endUpdates];
}
nduplessis
2009-09-08 07:23:04
I did above solution .But i got exception at insert row."Terminating app due to uncaught exception 'NSRangeException', reason: '*** -[NSMutableIndexSet addIndexesInRange:]: Range {2147483647, 1} exceeds maximum index value of NSNotFound - 1'".
diana
2009-09-08 08:56:26
Worked great!!!Tanxs lot.
diana
2009-09-08 09:51:40
Yeah sorry indexPathForRow:[dataSource count] should be indexPathForRow:([dataSource count] - 1)
nduplessis
2009-09-08 13:18:27