J'utilise une cellule personnalisée dans mon UITableView
, où je reçois des valeurs des objets que j'ajouter à cette cellule comme ceci:Attention - types de pointeurs incompatibles, comment supprimer?
NSIndexPath *indexPath = [self.ReportTableView indexPathForSelectedRow];
StuardReportCustomCell *cell = [_ReportTableView cellForRowAtIndexPath:indexPath];
NSString *text = cell.MyLabelInCell.text;
Tout travail bien mais j'ai un avertissement (ce qui est seulement 1 avertissement tout mon application) et je veux supprimer cet avertissement:
incompatible pointer types initializing StuardReportCustomCell with an expression of type
UITableviewCell
fichier de StuardReportCustomCell
#import <UIKit/UIKit.h>
@interface StuardReportCustomCell : UITableViewCell
@end
C'est cellForRowAtIndexPath
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *CellIdentifier = @"Cell";
StuardReportCustomCell *Cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if(!Cell){
Cell = [[StuardReportCustomCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier];
}
Cell.lbNum.text = [lbNum objectAtIndex:indexPath.row];
Cell.lbRouteNum.text = [lbRouteNum objectAtIndex:indexPath.row];
Cell.lbTime.text = [lbTime objectAtIndex:indexPath.row];
Cell.lbCity.text = [lbCity objectAtIndex:indexPath.row];
Cell.lbCameIn.text = [lbCameIn objectAtIndex:indexPath.row];
Cell.lbIn.text = [lbIn objectAtIndex:indexPath.row];
Cell.lbOut.text = [lbOut objectAtIndex:indexPath.row];
Cell.lbCameOut.text = [lbCameOut objectAtIndex:indexPath.row];
return Cell;
}
Solution:
StuardReportCustomCell *cell = (StuardReportCustomCell *)[_ReportTableView cellForRowAtIndexPath:indexPath];
ou
NSIndexPath *indexPath = [self.ReportTableView indexPathForSelectedRow];
NSString *text = [lbTime objectAtIndex:indexPath.row];
Il suffit de taper jeté 'StuardReportCustomCell * cellule = (StuardReportCustomCell *) [_ ReportTableView cellForRowAtIndexPath: indexPath];' –
@ MidhunMP Cela réglerait l'avertissement, mais il cacherait le vrai problème. – dasblinkenlight
@dasblinkenlight Où dans la question de l'OP at-il indiqué qu'il utilisait la réutilisation de cellules? – CrimsonChris