Adding a button to the bottom right of the screen:
UIButton *testBtn = [UIButton buttonWithType:UIButtonTypeRoundedRect];
[testBtn addTarget:self action:@selector(test:) forControlEvents:UIControlEventTouchUpInside];
CGRect screenRect = [[UIScreen mainScreen] bounds];
CGFloat screenWidth = screenRect.size.width;
CGFloat screenHeight = screenRect.size.height;
testBtn.frame = CGRectMake(screenWidth - 100, screenHeight - 100, 100, 100);
[self.view addSubview:testBtn];
I can see the button, and tapping it turns it blue momentarily. It just doesn’t call the test: method. Why not?
EDIT – here’s the target method:
- (void)test:(id)sender {
NSLog(@"hi");
}
lockBtnbut you are adding a target tobtn.@selector(test)and not@selector(test:).