문제

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