views:

73

answers:

1

I'm trying to make two custom buttons in code. One that fills the full screen with a small button on top. The problem I'm having is the larger button is triggered when the smaller button is tapped. I've tried doing exactly the same thing with IB and it works. Is there some sort of trapping/masking method that I need to use with code? I've checked the documentation and not come across anything that would suggest why this is happening.

CGRect bFrame = CGRectMake(0, 0, 320, 480);
UIButton *cancelButton = [[UIButton alloc] init];
cancelButton = [UIButton buttonWithType:UIButtonTypeCustom];
cancelButton.frame = bFrame;
[cancelButton setBackgroundColor:[UIColor clearColor]];
[cancelButton addTarget:self action:@selector(animate:) forControlEvents:UIControlEventTouchUpInside];      


UIButton *priceButton = [[UIButton alloc] init];
priceButton.center = CGPointMake(228, 98);
[priceButton addTarget:self action:@selector(callNumber:) forControlEvents:UIControlEventTouchUpInside];
[priceButton setTitle:@"BUY" forState:UIControlStateNormal];

[self.view addSubview:priceButton];
//[cancelButton addSubview:priceButton];
[self.view addSubview:cancelButton];
[self.view bringSubviewToFront:priceButton];
A: 

Did you forget to quote the [self.view addSubview:priceButton]; or is that simply missing in your code?

Till
Oops, it slipped off my paste. I had it in my original code. I've amended the code above.
Jim
Makes sense, just wanted to make sure. I should have written the above as a comment, not an answer as I have no further clue right now on why you are getting those results - my bad.
Till
Thanks for your input. Nice to know it' not something immediately obvious (apart from my paste).
Jim