不兼容的指针类型 Xcode

5
语义问题: 使用类型为UITableViewCell *的表达式来初始化NewCustomCell *的指针类型不兼容。
static NSString *cellID = @"customCell";

NewCustomCell *cell = [tableView dequeueReusableCellWithIdentifier:cellID];

NewCustomCell 是 UITableViewCell 的子类,对吗? - progrmr
1
看这个:7.赋值时的隐式向下转型 - albertamg
2个回答

12

[tableView dequeueReusableCellWithIdentifier:cellID] 返回一个类型为 UITableViewCell * 的对象。如果你知道这个单元格始终是 NewCustomCell * 类型,那么你可以使用强制转换告诉编译器去期望它的类型。像这样:

NewCustomCell *cell = (NewCustomCell *) [tableView dequeueReusableCellWithIdentifier:cellID];

3
你需要将它转换。
NewCustomCell *cell = (NewCustomCell *)[tableView dequeueReusableCellWithIdentifier:cellID];

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接