Как вставить строку в UITableView? - PullRequest
0 голосов
/ 05 января 2010

Я хочу использовать метод insertRowsAtIndexPaths для вставки строки в UITableView, но я не знаю, как сделать свойство indexPaths для этого метода.

Пожалуйста, помогите мне!

Ответы [ 2 ]

1 голос
/ 05 января 2010

Вы можете создать один NSIndexPath, используя

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

Ваш код для создания и заполнения параметра indexPaths может выглядеть следующим образом:

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
0 голосов
/ 05 января 2010
- (NSIndexPath *) indexPathForRow:(NSUInteger)row andSection:(NSUInteger)section {
    NSUInteger _path[2] = {section, row};
    NSIndexPath *_indexPath = [[NSIndexPath alloc] initWithIndexes:_path length:2];
    return [_indexPath autorelease];
}
Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...