【发布时间】:2016-06-13 22:02:14
【问题描述】:
我有一个 UITableViewCell 的子类,称为 ReminderCell。
ReminderCell 有一个我写的叫做backToPlaceAnimation 的方法。
问题是,例如,如果我想在第一个 ReminderCell 上使用 RemindersVC 调用 backToPlaceAnimation 并使用 tableView: cellForRowAtIndexPath: 它没有返回正确的对象(它是 UITableViewCell 对象而不是 ReminderCell) .
我怎样才能得到正确的对象?
代码:
NSIndexPath *cellIndexPath=[NSIndexPath indexPathWithIndex:0];
ReminderCell *cell=(ReminderCell*)[self tableView:self.AroundersTableView cellForRowAtIndexPath:cellIndexPath];
[cell cancelDeletion];
崩溃日志:
*** Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'Invalid index path for use with UITableView. Index paths passed to table view must contain exactly two indices specifying the section and row. Please use the category on NSIndexPath in UITableView.h if possible.
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;
}
谢谢!
【问题讨论】:
-
显示一些关于如何从
cellForRowAtIndexPath获取单元格的代码 -
您是否以编程方式创建 UITableView?
-
@DantePuglisi 更新帖子,请看一下
-
@BlackMagic 不,我正在使用故事板
-
你能显示你的 CellForRowAtIndexPath 代码吗?还是你的 UITableView 是固定大小的?
标签: ios objective-c iphone uitableview cocoa-touch