Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Unrecognized Selector Sent to instance while adding a subview

Tags:

xcode4.2

I am getting this thread while running my app.

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' is called my subclass.

In cell.h i have

@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

And in my calling class i have SIAViewcontroller.h

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

In its implementation 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.
}

What Would be the reason for this? Can anybody help?

like image 627
Deepak Sasindran Avatar asked Dec 13 '25 06:12

Deepak Sasindran


1 Answers

Your cell class should extend UIView rather than UIViewController.

@interface cell : UIView

UIView provides a superview property, while UIViewController does not, triggering the "unrecognized selector" crash.

like image 55
Sergey Kalinichenko Avatar answered Dec 16 '25 22:12

Sergey Kalinichenko



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!