Incompatible pointer types Xcode

♀尐吖头ヾ 提交于 2019-12-07 05:53:54

问题


Semantic Issue: Incompatible pointer types initializing NewCustomCell * with an expression of type UITableViewCell *

static NSString *cellID = @"customCell";

NewCustomCell *cell = [tableView dequeueReusableCellWithIdentifier:cellID];

回答1:


[tableView dequeueReusableCellWithIdentifier:cellID] returns an object with type UITableViewCell *. If you know that the cell will always be of type NewCustomCell *, then you can tell the compiler to expect that with a cast. Like so:

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



回答2:


You have to cast it.

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


来源:https://stackoverflow.com/questions/7220940/incompatible-pointer-types-xcode

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!