Incompatible pointer type initializing 'CustomCellView *' with an expression of type UItableViewCell

匿名 (未验证) 提交于 2019-12-03 02:50:02

问题:

Can you help me understandand/fix the error below. I don't understand as CustomCellView is a subclass of UItableViewCell. The code gets compiled but the warning is still there:

Incompatible pointer type initializing 'CustomCellView *' with an expression of type `UItableViewCell` 

I got the 2nd line below hightlighted:

static NSString *CellIdentifier = @"CustomCell"; CustomCellView *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier]; 

回答1:

static NSString *CellIdentifier = @"CustomCell"; CustomCellView *cell =(CustomCellView*) [tableView dequeueReusableCellWithIdentifier:CellIdentifier]; 

you need to type cast to your cell



回答2:

static NSString *CellIdentifier = @"CustomCell"; CustomCellView *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier forIndexPath:indexPath]; 


回答3:

For custom cell below code is also working fine with given frame..

  CustomCell *cell= [[[CustomCell alloc] initWithFrame:CGRectZero reuseIdentifier:nil] autorelease]; 


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