简体   繁体   English

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

[英]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;
}
  1. You need to cast dequeueReusableCellWithIdentifier to the proper class. 您需要将dequeueReusableCellWithIdentifier转换为适当的类。
  2. When you create a new cell, it needs to be of the proper type. 创建新单元格时,它必须是正确的类型。

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.

相关问题 不兼容的指针类型从“ UIPopoverController *”分配给“ UIDatePicker *” - Incompatible pointer types assigning to 'UIDatePicker *' from 'UIPopoverController *' 从'nsarray'分配给'nsmutablearray'的不兼容指针类型 - incompatible pointer types assigning to 'nsmutablearray ' from 'nsarray ' 不兼容的指针类型从NSArray分配给NSMutableString - Incompatible pointer types assigning to NSMutableString from NSArray 从“ CCTMXLayer *”分配给“ CCTMXTiledMap *”的指针类型不兼容 - Incompatible pointer types assigning to 'CCTMXTiledMap*' from 'CCTMXLayer*' 不兼容的指针类型从NSString分配给“ UITextField” - Incompatible pointer types assigning to “UITextField” from NSString 从“ NSData *”分配给“ NSMutableData *”的指针类型不兼容 - Incompatible pointer types assigning to 'NSMutableData *' from 'NSData *' 从用户*分配给NSArray *的指针类型不兼容 - Incompatible pointer types assigning to NSArray * from User * 从“ NSMutableArray *”分配给“ NSString *”的指针类型不兼容 - Incompatible pointer types assigning to 'NSString *' from 'NSMutableArray *' 不兼容的指针类型从NSExpression分配给MGLStyleValue - Incompatible pointer types assigning to MGLStyleValue from NSExpression 从nsdictionary分配给nsarray的不兼容指针类型 - incompatible pointer types assigning to nsarray from nsdictionary
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM