0
我有一个tableview。我需要在加载后的特定时间间隔内添加tableview的单元格,以便我们可以查看加载单元格。如何才能做到这一点。任何想法将不胜感激!在特定的时间间隔添加tableview单元格
我有一个tableview。我需要在加载后的特定时间间隔内添加tableview的单元格,以便我们可以查看加载单元格。如何才能做到这一点。任何想法将不胜感激!在特定的时间间隔添加tableview单元格
设置一个计时器在你的UITableViewController您的viewDidLoad方法,像这样:
- (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];
}
然后插入新行到我们的数据源,并告诉的tableView它
- (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];
}
我上面的解决方案做了但是我在插入行得到了异常。“由于未捕获异常'NSRangeException',原因:'*** - [NSMutableIndexSet addIndexesInRange:]:范围{2147483647,1}超过了NSNotFound - 1'”的最大索引值。 – diana 2009-09-08 08:56:26
工作很好!!! Tanxs很多。 – diana 2009-09-08 09:51:40
对不起indexPathForRow:[dataSource count]应该是indexPathForRow:([dataSource count] - 1) – nduplessis 2009-09-08 13:18:27