2012-07-07 72 views
-4

我在我的項目中有兩個班級:SIAViewController.h及其子班級cell.h我如何修復警告

cell.h

@interface cell : UIViewController 
@property(nonatomic)CGRect frame; 
@property(assign,nonatomic)UIImage *image; 
@property(nonatomic)int tag; 
@property(nonatomic)bool userInteractionEnabled; 
@property(retain,nonatomic)UITapGestureRecognizer *addGestureRecognizer; 
@end 

而且在SIAViewController.m

int x=20,y=50,t=1; 
cell *tank[9][9]; 
for(int i=1;i<=8;i++) 
{ 
    for(int j=1;j<=8;j++) 
    { 
     tank[i][j]=[[cell alloc]init]; 
     tank[i][j].frame=CGRectMake(x, y, 35, 35); 
     UIImage *myImage=[UIImage imageNamed:@"s.jpg"]; 
     [tank[i][j] setImage:myImage]; 
     tank[i][j].tag=t; 
     tank[i][j].userInteractionEnabled=YES; 
     UITapGestureRecognizer * recognizer = [[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(tapDetected:)]; 
     tank[i][j]. addGestureRecognizer=recognizer; 
     [self.view addSubview:tank[i][j]]; 
     x+=35; 
     t++; 
    } 
    y+=35; 
    x=20; 
} 

,當運行這個項目我收到線不兼容的指針類型的細胞發送到__strong類型的UIView的參數。誰能幫我。我是xcode的新手。謝謝

回答

1

原因是,UIView是你的表視圖單元格的超類。這意味着如果某些屬性應該是UITableViewCell,但是您傳遞的是通用UIView實例,則該UIView可能(但不一定)也是UITableViewCell。這就是編譯器警告你的原因。如果您知道您要設置的實例實際上是僞裝成UIView的UITableViewCell,那麼您可以放心地忽略此警告,因爲Objective-C是一種動態語言;類型聲明只是爲了欺騙編譯器;類型匹配在運行時發生。

+0

看到我收到線程終止應用程序,由於未捕獲的異常'NSInvalidArgumentException',原因:' - [cell superview]:無法識別的選擇器發送到實例0x68441d0' – Shaan 2012-07-09 06:37:13