开发者

UITableView: Section identifier problem

I have an UITableview with a lot of sections with a dynamic amount of rows with a dynamic height. Now i got the following Problem:

[indexPath section] returns the value of the (latest/ lowest/ highest-value) section in the view. Now i have a section witch is very small and i can unfortunately "see"开发者_运维百科 3 sections in one time. How can i identify the section on top? Any ideas. I need it because in every section are buttons which cause a change of the amount of Rows in the section ( depending on the section). Sometimes i increase the amount of Rows for wrong sections because i cannot identify the 'upper' section.

I hope i described it good enough.


You can get all the visible cells using the visibleCells method of the table view. You will need to sort the array to be sure.

NSArray * visibleCells = [self.tableView visibleCells];
NSArray * sortedVisibleCells = [visibleCells sortedArrayUsingComparator:^NSComparisonResult(id obj1, id obj2) {
    NSIndexPath * indexPath1 = [self.tableView indexPathForCell:obj1];
    NSIndexPath * indexPath2 = [self.tableView indexPathForCell:obj2];

    return [indexPath1 compare:indexPath2];
}];

NSLog(@"%@", [self.tableView indexPathForCell:[sortedVisibleCells objectAtIndex:0]]);
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜