motionpotion
motionpotion

Reputation: 2736

didSelectRowAtIndexPath With Custom Cell

I have subclassed UITableViewCell to create a custom cell. On a ViewController I have added a UITableView and a prototype cell. My custom cell appears and works fine.

But in my didSelectRowAtIndexPath and didDeselectRowAtIndexPath methods a warning appears that I cannot get rid of.

-(void)tableView:(UITableView *)tableView didDeselectRowAtIndexPath:(NSIndexPath *)indexPath {

MVGoalTVCell *cell = [self.tableView cellForRowAtIndexPath:indexPath];
NSString *cellText = cell.txtBox.text;

LogInfo(@"DESELECTED: %@", cellText);

}

-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{

MVGoalTVCell *cell = [self.tableView cellForRowAtIndexPath:indexPath];
NSString *cellText = cell.txtBox.text;

LogInfo(@"SELECTED: %@", cellText);

}

The warning appears on the line:

MVGoalTVCell *cell = [self.tableView cellForRowAtIndexPath:indexPath];

I am referencing my custom cell in MVGoalTVCell.

The warning that appears is as follows:

Incompatible pointer types initializing 'MVGoalTVCell *' with an expression of type 'UITableViewCell *'

How can I fix this warning?

Upvotes: 1

Views: 3245

Answers (1)

hv88
hv88

Reputation: 328

Use typecasting to fix the warning.

MVGoalTVCell *cell = (MVGoalTVCell *)[self.tableView cellForRowAtIndexPath:indexPath];

Upvotes: 9

Related Questions