ios - 如何调用 tableView :cellForRowAtIndexPath: safely in UITableView?

标签 ios ios6 uitableview

我已经在 Storyboard 中设置了一个带有原型(prototype)单元格的表格 View 。
现在我想编辑单元格的 subview ,如果它被滑动,所以我实现了委托(delegate)方法 tableView:willBeginEditingRowAtIndexPath:。
如何从该方法中获取正在编辑的当前单元格?如果我使用 tableView:cellForRowAtIndexPath: 我会得到一个新单元格,而不是我需要的单元格,因为随后对 dequeueReusableCellWithIdentifier:forIndexPath: 的调用似乎会为相同的标识符和 indexPath 返回不同的对象。

我可以使用以下代码轻松重现此行为:

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"Cell" forIndexPath:indexPath];
    NSLog(@"cell = %@", cell);
    cell = [tableView dequeueReusableCellWithIdentifier:@"Cell" forIndexPath:indexPath];
    NSLog(@"different cell = %@", cell);
}

那么当我不能使用这个方法时,如何获取当前放置在特定 indexPath 的单元格呢?
我正在使用 iOS 6。

最佳答案

- (UITableViewCell *)cellForRowAtIndexPath:(NSIndexPath *)indexPath
UITableView

关于ios - 如何调用 tableView :cellForRowAtIndexPath: safely in UITableView?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16811751/

相关文章:

ios - TableView 未知阴影错误

ios - Swift:在动画期间中途更改 UIImageView 图像

ios - iOS 应用程序中的点赞按钮

iphone - 应用程序图标出现在应用程序模拟器上但不出现在设备上

iphone - 在一台设备上为多个用户登录 iOS 应用程序中的 Facebook

xcode - 将 UIView 放置在其他两个 View 之间。自动布局

ios - Swift:延迟 UITableViewCell 选择

ios - 在哪里添加事件处理程序

swift - 单元格中的完成处理程序

ios - 设备锁定时无法在路径上打开 Realm