Reputation: 6347
I'm still a bit green in iOS development and keep getting a warning that I'm not sure about.
I am using a custom cell in a tableview and have set its class to be a subclass of UITableViewCell called SiteCell. In my "didSelectRowAtIndexPath" method when I declare the selected cell as a SiteCell type, I receive the following warning:
Incompatible pointer types initializing SiteCell __strong with an expression of type UITableViewCell
-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
SiteCell *cell = [tableView cellForRowAtIndexPath:indexPath];
NSString *rowIdentity = [NSString stringWithFormat:@"%d", indexPath.row];
[selectedRows setObject:[cell.siteTitleLabel text] forKey:rowIdentity];
if(cell.accessoryType == UITableViewCellAccessoryCheckmark){
cell.accessoryType = UITableViewCellAccessoryNone;
}else{
cell.accessoryType = UITableViewCellAccessoryCheckmark;
}
}
Can anyone shed any light on how to get rid of this warning?
Upvotes: 3
Views: 7681
Reputation: 477
The right way to do it. You need NSIndexPath
SiteCell *cell = (SiteCell *) [self.tableView cellForRowAtIndexPath:[NSIndexPath indexPathForRow:row inSection:section]];
Upvotes: 1
Reputation: 5745
Your code should be this since you have to cast the UITableViewCell
to your subclass SiteCell
SiteCell *cell = (SiteCell *)[tableView cellForRowAtIndexPath:indexPath];
Upvotes: 3
Reputation: 47699
Assuming that cellForRowAtIndexPath is properly coded, and is known to always return a SiteCell
, you simply need to cast to SiteCell*
:
SiteCell *cell = (SiteCell*)[tableView cellForRowAtIndexPath:indexPath];
Upvotes: 16