[英]Incompatible pointer types assigning to 'TableViewCell' from 'UITableViewCell'
I am trying this code and getting below warning 我正在尝试此代码并得到警告以下
Incompatible pointer types assigning to 'GuideTableViewCell' from 'UITableViewCell'
不兼容的指针类型从“ UITableViewCell”分配给“ GuideTableViewCell”
in line 排队
cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"BusinessTableViewCell"];
Full Code: 完整代码:
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
BusinessTableViewCell * cell = [self.tableView dequeueReusableCellWithIdentifier:@"BusinessTableViewCell"];
if (!cell) {
cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"BusinessTableViewCell"];
}
BusinessInfo * business = self.businesses[indexPath.row];
cell.business = business;
return cell;
}
Also tried 也尝试过
BusinessTableViewCell *cell = [[UITableViewCell alloc]initWithStyle: UITableViewCellStyleDefault reuseIdentifier:@"BusinessTableViewCell"];
still getting the error can any one kindly give me some help. 仍然遇到错误,任何人都可以给我一些帮助。
thanks 谢谢
You have two issues in your code. 您的代码中有两个问题。 It should be:
它应该是:
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
BusinessTableViewCell * cell = (BusinessTableViewCell *)[self.tableView dequeueReusableCellWithIdentifier:@"BusinessTableViewCell"];
if(!cell)
{
cell = [[BusinessTableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"BusinessTableViewCell"];
}
BusinessInfo * business = self.businesses[indexPath.row];
cell.business = business;
return cell;
}
dequeueReusableCellWithIdentifier
to the proper class. dequeueReusableCellWithIdentifier
转换为适当的类。 You get an error because your code cannot possibly work. 您收到错误,因为您的代码可能无法正常工作。
Your code expects a BusinessTableViewCell. 您的代码需要一个BusinessTableViewCell。 You create a UITableViewCell.
您创建一个UITableViewCell。 You should be creating a BusinessTableViewCell.
您应该创建一个BusinessTableViewCell。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.