不兼容的指针类型 Xcode

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/7220940/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-14 21:49:31  来源:igfitidea点击:

Incompatible pointer types Xcode

objective-ciosxcodexcode4

提问by Rollo

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

语义问题:使用类型NewCustomCell *表达式初始化的不兼容指针类型UITableViewCell *

static NSString *cellID = @"customCell";

NewCustomCell *cell = [tableView dequeueReusableCellWithIdentifier:cellID];

回答by Pontus Granstr?m

[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:

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

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

回答by Daniel A. White

You have to cast it.

你必须投它。

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