繁体   English   中英

不兼容的指针类型从“ UITableViewCell”分配给“ TableViewCell”

[英]Incompatible pointer types assigning to 'TableViewCell' from 'UITableViewCell'

我正在尝试此代码并得到警告以下

不兼容的指针类型从“ UITableViewCell”分配给“ GuideTableViewCell”

排队

cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"BusinessTableViewCell"];

完整代码:

- (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;
}

也尝试过

BusinessTableViewCell *cell = [[UITableViewCell alloc]initWithStyle: UITableViewCellStyleDefault reuseIdentifier:@"BusinessTableViewCell"];

仍然遇到错误,任何人都可以给我一些帮助。

谢谢

您的代码中有两个问题。 它应该是:

- (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;
}
  1. 您需要将dequeueReusableCellWithIdentifier转换为适当的类。
  2. 创建新单元格时,它必须是正确的类型。

您收到错误,因为您的代码可能无法正常工作。

您的代码需要一个BusinessTableViewCell。 您创建一个UITableViewCell。 您应该创建一个BusinessTableViewCell。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM