I have a view controller (vc1) that uses another class in order to get UI-elements. So the view of vc1 sets as subview another view returned from a class called Layout. The view returned from the class Layout contains a UIbutton. In the Layout class I have this code:
[btn addTarget:self action:@selector(button_clicked:) forControlEvents:UIControlEventTouchUpInside];
Then in the same class (Layout) I also declared the method button_clicked:
- (void)button_clicked:(id)sender {
NSLog(@"btn clickd");
}
However, when I click the button something wrong happens. I cannot see any error message in debug area but the state of Xcode doesn't look good. The simulator loses focus and Xcode appears with a file (I guess its AppDelegate.m) with this line:
@autoreleasepool {
return UIApplicationMain(argc, argv, nil, NSStringFromClass([AppDelegate class]));
}
highlighted with green color. Also, in the code I see the message:
Thread 1: EXC_BAD_ACCESS(code=2, adress=0x9)
What could be wrong? I also am afraid that vc1 should manage the button click, so the method I think would be best to be placed inside vc1. Dont you think so?