Iphone 按特定时间间隔添加tableview单元格

Iphone 按特定时间间隔添加tableview单元格,iphone,objective-c,uikit,Iphone,Objective C,Uikit,我有一个桌面视图。我需要在加载后的特定时间间隔添加tableview的单元格,以便我们可以查看加载单元格的情况。我如何才能做到这一点。任何想法都将不胜感激 在UITableViewController的viewDidLoad方法中设置计时器,如下所示: - (void)viewDidLoad { [super viewDidLoad]; // Schedule a timer to fire every 5 seconds and call our // insertN

我有一个桌面视图。我需要在加载后的特定时间间隔添加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 AddIndexInRange::]:范围{2147483647,1}超过了NSNotFound的最大索引值-1'。是的,很抱歉indexPathForRow:[数据源计数]应该是indexPathForRow:([dataSource计数]-1)