开发者

how to detect which rows are shown in UItableview

I want to update accessoryViews in UITableView, but just on the rows, which the user can a开发者_如何学编程ctually see.

How can I detect which rows are actually on the screen?


Make use of UITableview instance method -visibleCells

visibleCells

Returns the table cells that are visible in the receiver.

- (NSArray *)visibleCells

Return Value

An array containing UITableViewCell objects, each representing a visible cell in the receiving table view.

Availability

Available in iOS 2.0 and later.


UITableView has -visibleCells method for that - it returns a NSArray of currently visible cells


Implement this for which row you want not to add accessory.

-(NSIndexPath *)tableView:(UITableView *)tableView willSelectRowAtIndexPath:(NSIndexPath *)indexPath {

NSUInteger row = [indexPath row];
if (row == 0||row == 2)
    return nil;
return indexPath;
}


Don't think you really need to detect visible row for updating accessoryViews. You can just implement it in the tableView:cellForRowAtIndexPath: datasource method.

But if you want to get the visible rows you can use

- (NSArray *)visibleCells
0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜