2012-07-10 27 views
3

我在運行我的應用程序時得到此線程。無法識別的選擇器在添加子視圖時發送到實例

2012-07-10 15:44:39.668 DSSAmple[447:f803] -[cell superview]: unrecognized selector sent  to instance 0x68b4080 
2012-07-10 15:44:39.671 DSSAmple[447:f803] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[cell superview]: unrecognized selector sent to instance 0x68b4080' 

'cell'被稱爲我的子類。

在cell.hi有

@interface cell : UIViewController 
{ 
UIImage *MyImage; 
int row; 
int column; 
CGRect frame; 
} 
@property(retain,nonatomic)UIImage *MyImage; 
@property(assign,nonatomic)int row; 
@property(assign,nonatomic)CGRect frame; 
@property(assign,nonatomic)int column; 
@end 

在我調用類我有 SIAViewcontroller.h

#import <UIKit/UIKit.h> 
#import "cell.h" 
@interface SIAViewController : UIViewController 
-(void)PanelLoading; 
@end 

在其實施 SIAViewController.m

-(void)PanelLoading 
{ 
UIImage *myImage=[UIImage imageNamed:@"s.jpg"]; 
int x=20,y=50,r=1,c=1; 
for (int i=1; i<=8; i++) 
{ 
    for (int j=1; j<=8; j++) 

    { 
     cell *tank=[[cell alloc]init]; 
     tank.column=c; 
     tank.row=r; 
     tank.frame=CGRectMake(x, y, 35, 35); 
     tank.MyImage=myImage; 
     [self.view addSubview:tank]; 
     x+=35; 
     r++; 
    } 
    r=1; 
    c++; 
    y+=35; 
    x=20; 
} 

} 

- (void)viewDidLoad 
{ 
[super viewDidLoad]; 
[self PanelLoading]; 
// Do any additional setup after loading the view, typically from a nib. 
} 

會是什麼成爲這個的原因?任何人都可以幫忙嗎?

回答

2

您的cell類應延伸UIView而不是UIViewController

@interface cell : UIView 

UIView提供superview屬性,而UIViewController沒有,觸發 「無法識別選擇」 崩潰。

+0

好的。非常感謝你。我明白,但仍然沒有顯示任何東西 – 2012-07-10 11:23:13

+0

@Deepak這是一個單獨的問題。我的猜測是,這是因爲你的'cell'沒有在它的超級視圖上繪製自己。你重寫了' - (void)drawRect:(CGRect)rect'?我甚至不確定你的'cell'是否設計得最佳:你可以使用'UIImageView'而不是自定義的'cell'視圖嗎? – dasblinkenlight 2012-07-10 11:30:40

相關問題