iphone - 检查特定的 UITableViewCell 在 UITableView 中是否可见

标签 iphone objective-c ios xcode uitableview

我有一个 UITableView 和一些 UITableViewCells,它们是我通过 Interface Builder 手动创建的。我已经为每个单元格分配了一个 outlet,并在 CellForRowAtIndexPath 方法中将它们连接到 UITableView。在此方法中,我使用 switch(case) 方法使特定单元格出现在 UITableView 中,具体取决于大小写。

现在,我想找到一个特定的单元格并检查他是否存在于 UITableView 中。我使用方法:UITableView.visibleCells 来获取 TableView 中的单元格数组。我的问题是 - 如何检查数组中是否存在特定单元格?我能以某种方式使用分配给它的 socket 吗? -(最佳解决方案),或者,我可以使用标识符吗?如何使用?

谢谢:)

最佳答案

请注意,您也可以这样使用 indexPathsForVisibleRows:

    NSUInteger index = [_people indexOfObject:person];
    NSIndexPath *indexPath = [NSIndexPath indexPathForRow:index inSection:0];
    if ([self.tableView.indexPathsForVisibleRows containsObject:indexPath]) {
      [self.tableView reloadRowsAtIndexPaths:[NSArray arrayWithObject:indexPath] 
                            withRowAnimation:UITableViewRowAnimationFade];
    }

如果您有 indexPath(并且不需要实际的 Cell),它可能便宜

PS:_people 是在这种情况下用作我的后端的 NSArray

关于iphone - 检查特定的 UITableViewCell 在 UITableView 中是否可见,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8052999/

相关文章:

Objective-C:Cocoa 应用程序可以是 "menu only"应用程序吗?

ios - 使用加密的 CoreData 实现时是否需要 shm 和 wal 文件?

ios - user-scalable=no 不起作用,是否仍受支持?

iphone - "unrecognized selector sent to instance"当键盘出现时

iphone - UIAlertView 按钮标记

iphone - ":"标记之前的预期表达式

ios - 在UIViewController上添加按钮时出错:“NSUnknownKeyException”

iphone - 带大括号的 NSURL

iphone - 是否可以让 XCode 中的 Interface Builder 自动创建支持 IBAction?

ios - 将自动布局与动态 UITextView、UIImageView 和 UILabel 高度一起使用