簡體   English   中英

如何在UITableView中插入一行?

[英]How to insert a row to a UITableView?

我想使用insertRowsAtIndexPaths方法將一行插入到UITableView中,但是我不知道如何為該方法制作“ indexPaths”屬性。

請幫我!

您可以使用創建單個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
- (NSIndexPath *) indexPathForRow:(NSUInteger)row andSection:(NSUInteger)section {
    NSUInteger _path[2] = {section, row};
    NSIndexPath *_indexPath = [[NSIndexPath alloc] initWithIndexes:_path length:2];
    return [_indexPath autorelease];
}

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM