ios - 返回 UITableViewCell 自定义单元格

标签 ios objective-c iphone uitableview cocoa-touch

我有一个名为 ReminderCellUITableViewCell 子类。

ReminderCell 有一个名为 backToPlaceAnimation 的方法,是我编写的。

例如,如果我想使用 RemindersVC 在第一个 ReminderCell 上调用 backToPlaceAnimation,使用 tableView: cellForRowAtIndexPath: 它没有返回正确的对象(它是 UITableViewCell 对象,根本不是 ReminderCell)。

如何获得正确的对象?

代码:

NSIndexPath *cellIndexPath=[NSIndexPath indexPathWithIndex:0];

ReminderCell *cell=(ReminderCell*)[self tableView:self.AroundersTableView cellForRowAtIndexPath:cellIndexPath];

[cell cancelDeletion];

崩溃日志:

*** 由于未捕获的异常“NSInternalInconsistencyException”而终止应用程序,原因:“用于 UITableView 的索引路径无效。传递给 TableView 的索引路径必须恰好包含两个指定部分和行的索引。如果可能,请在 UITableView.h 中使用 NSIndexPath 上的类别。

cellForRowAtIndexPath:覆盖:

-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    //Creating a default cell using "cellIdentifier"(NSString)
    ReminderCell *cell=[tableView dequeueReusableCellWithIdentifier:@"Cell"];
    if (cell==nil) {
        cell=[[ReminderCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"Cell"];
    }
    //Changing "cell"'s "index" to indexPath.row
    cell.index=(int)indexPath.row; //Crashes here

    cell.textLabel.text=@"Hello";

    //Returning cell
    return cell;
}

谢谢!

最佳答案

您应该将 [NSIndexPath indexPathWithIndex:0]; 替换为 [NSIndexPath indexPathWithIndex:0 inSection:0];

关于ios - 返回 UITableViewCell 自定义单元格,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35723711/

相关文章:

ios - 为什么关闭 UIAlertController 会调用 UINavigationController 上的关闭?

ios - 委托(delegate)不会执行功能

ios - 采用 Objective-C iOS 的多种协议(protocol)

iphone - 支持开发的 iOS 设备的性能是否受到影响?

iphone - 未显式调用 Objective-C 版本

ios - 区分选项卡与点击 UITextField 条目?

android - 不同的移动操作系统和数据库

asp.net - ASP.NET 中的 iPhone Web 应用程序开发 - 从哪里开始?

ios - NSString stringWithFormat 添加了 "ffffff"

c++ - 获取所有可能的组合数