I canโt believe that I am tripping on something very simple:
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil { self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil]; if (self) { UIButton *button = [UIButton buttonWithType:UIButtonTypeRoundedRect]; [button setTitle:@"Tap me" forState:UIControlStateNormal]; [button addTarget:self action:@selector(test) forControlEvents:UIControlEventTouchUpInside]; button.frame = CGRectMake(50, 50, 120, 60); [self.view addSubview:button]; } return self; } -(void)test { NSLog(@"Test"); }
Failed to click a button with an error unrecognized selector sent to instance .
Does anyone know what I can do wrong here?
Edit - error message:
-[__NSCFString test]: unrecognized selector sent to instance 0x29ee30 *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[__NSCFString test]: unrecognized selector sent to instance 0x29ee30'
Edit - how it is presented (ARC):
DemoViewController *demoVC = [[DemoViewController alloc] init]; [self.window addSubview:demoVC.view]; [self.window makeKeyAndVisible];
source share