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
精彩评论