views:

284

answers:

1

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
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
Worked great!!!Tanxs lot.
diana
Yeah sorry indexPathForRow:[dataSource count] should be indexPathForRow:([dataSource count] - 1)
nduplessis