Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/iphone/42.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Iphone 如何将行插入UITableView?_Iphone_Cocoa Touch - Fatal编程技术网

Iphone 如何将行插入UITableView?

Iphone 如何将行插入UITableView?,iphone,cocoa-touch,Iphone,Cocoa Touch,我想使用insertRowsAtIndexPaths方法向UITableView插入一行,但我不知道如何为此方法创建“indexPaths”属性 请帮帮我 您可以使用 + (NSIndexPath *)indexPathForRow:(NSUInteger)row inSection:(NSUInteger)section; // defined in UITableView.h 创建和填充indexPaths参数的代码可能如下所示: NSMutableArray* indexPaths =

我想使用insertRowsAtIndexPaths方法向UITableView插入一行,但我不知道如何为此方法创建“indexPaths”属性


请帮帮我

您可以使用

+ (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

它很有用!非常感谢,弗拉基米尔
- (NSIndexPath *) indexPathForRow:(NSUInteger)row andSection:(NSUInteger)section {
    NSUInteger _path[2] = {section, row};
    NSIndexPath *_indexPath = [[NSIndexPath alloc] initWithIndexes:_path length:2];
    return [_indexPath autorelease];
}