我需要获取 UITableView 中所有单元格的数组。我目前使用以下方法:
-(NSArray *)allTableViewCellsArray
{
NSMutableArray *cells = [[NSMutableArray alloc] init];
for (NSInteger j = 0; j < [tableView numberOfSections]; ++j)
{
for (NSInteger i = 0; i < [tableView numberOfRowsInSection:j]; ++i)
{
[cells addObject:[tableView cellForRowAtIndexPath:[NSIndexPath indexPathForRow:i inSection:j]]];
}
}
return cells;
}
我已经取得了一些成功,但是我发现当单元格不可见时它会崩溃。那么,无论它们是否可见,如何获取 UITableView 中所有单元格的数组?