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