尝试这个,
- (void)viewDidLoad
{
[super viewDidLoad];
UIButton *firstButton=[UIButton buttonWithType:UIButtonTypeRoundedRect];
[firstButton setTitle:@"first" forState:UIControlStateNormal];
firstButton.frame=CGRectMake(40, 70, 80, 80);
[firstButton addTarget:self action:@selector(firstButtonClicked) forControlEvents: UIControlEventTouchUpInside];
[self.view addSubview:firstButton];
UIView *view=[[UIView alloc]initWithFrame:CGRectMake(0, 0, 80, 80)];
[firstButton addSubview:view];
UIButton *secondButton=[UIButton buttonWithType:UIButtonTypeRoundedRect];
[secondButton setTitle:@"second" forState:UIControlStateNormal];
secondButton.frame=CGRectMake(0, 0, 80, 80);
[secondButton addTarget:self action:@selector(secondButtonClicked) forControlEvents: UIControlEventTouchUpInside];
[view addSubview:secondButton];
// Do any additional setup after loading the view, typically from a nib.
}
-(void)firstButtonClicked {
NSLog(@"first");
}
-(void)secondButtonClicked {
NSLog(@"second");
}