I tried the codes of Moshe in this link, and it worked except the part of "for (UIButton *button in ..." and it crashes every time when I click on a button.
So I tried this code in the viewDidLoad method:
UIButton *testButton = [[UIButton alloc]initWithFrame:CGRectMake(20,50,30,30)];
testButton.backgroundColor = [UIColor orangeColor];
[testButton setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
[testButton setTitle:@"A" forState:UIControlStateNormal];
[testButton addTarget:self action:@selector(commonMethodForButtons:) forControlEvents:UIControlEventTouchDown];
[self.view addSubview:testButton];
[testButton release];
My project contains nothing than this and Moshe´s sample codes. Any idea why the app crashes? I get no crash log.
EDIT:
in the open scope I have this method:
-(void)commonMethodForButtons:(id)sender
{
NSLog (@"you touched me!");
}
EDIT 2:
I found the reason to this problem:
I commented out [mvc release];
in AppDelegate, so it works perfectly now :)
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
// Override point for customization after application launch.
MVC *mcv = [[MVC alloc]initWithNibName:nil bundle:nil];
[self.window addSubview: mcv.view];
//[mcv release];
[self.window makeKeyAndVisible];
return YES;
}
Thank you for pointing this out! :)