views:

91

answers:

2

I want to use insertRowsAtIndexPaths method to insert a row to a UITableView, but I don't know how to make "indexPaths" property for this method.

Please help me!

+1  A: 

You can create single NSIndexPath using

+ (NSIndexPath *)indexPathForRow:(NSUInteger)row inSection:(NSUInteger)section; // defined in UITableView.h

Your code to create and fill indexPaths paramater may look like:

NSMutableArray* indexPaths = [NSMutableArray arrayWithCapacity:10];
for (...) // iterate to get all indexes and section you need
{
   [indexPaths addObject:[NSIndexPath indexPathForRow:someRow inSection:someSection]];
}
//indexPaths is ready to use
Vladimir
It's useful! Thank so much, Vladimir
hungbm06
A: 
- (NSIndexPath *) indexPathForRow:(NSUInteger)row andSection:(NSUInteger)section {
    NSUInteger _path[2] = {section, row};
    NSIndexPath *_indexPath = [[NSIndexPath alloc] initWithIndexes:_path length:2];
    return [_indexPath autorelease];
}
Alex Reynolds
Alex, thank for help!
hungbm06