سؤال

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?

هل كانت مفيدة؟

المحلول

Use typecasting to fix the warning.

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

مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top