以特定时间间隔添加tableview单元格

时间:2009-09-08 07:04:55

标签: iphone objective-c uikit

我有一个tableview。我需要在加载后的特定时间间隔添加tableview的单元格,以便我们可以查看加载单元格。我怎么能这样做。任何想法将不胜感激!

1 个答案:

答案 0 :(得分:1)

在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];
}