1
我使用的是自定義單元格在我UITableView
,在那裏我收到的對象值什麼,我到這個小區是這樣的:警告 - 不兼容的指針類型,如何刪除?
NSIndexPath *indexPath = [self.ReportTableView indexPathForSelectedRow];
StuardReportCustomCell *cell = [_ReportTableView cellForRowAtIndexPath:indexPath];
NSString *text = cell.MyLabelInCell.text;
所有工作不錯,但我有一個警告(這是隻有1個警告我所有的應用程序),我想刪除這個警告:
incompatible pointer types initializing StuardReportCustomCell with an expression of type
UITableviewCell
StuardReportCustomCell .h文件中
#import <UIKit/UIKit.h>
@interface StuardReportCustomCell : UITableViewCell
@end
這是的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;
}
解決方案:
StuardReportCustomCell *cell = (StuardReportCustomCell *)[_ReportTableView cellForRowAtIndexPath:indexPath];
或
NSIndexPath *indexPath = [self.ReportTableView indexPathForSelectedRow];
NSString *text = [lbTime objectAtIndex:indexPath.row];
只需鍵入投'StuardReportCustomCell *電池=(StuardReportCustomCell *)[_ ReportTableView的cellForRowAtIndexPath:indexPath]' –
@ MidhunMP這將修復警告,但它會隱藏真正的問題。 – dasblinkenlight
@dasblinkenlight在OP的問題中,他表示他在使用單元重用? – CrimsonChris