objective c 手动创建按钮并绑定事件处理程序

- (void)createButton {   UIButton *myButton = [UIButton buttonWithType:UIButtonTypeRoundedRect]; myButton.frame = CGRectMake(100, 100, 100, 50); [myButton setTitle:@"click me!" forState:UIControlStateNormal]; SEL eventHandler = @selector(clickHandler); [myButton addTarget:self action:eventHandler forControlEvents:UIControlEventTouchUpInside]; [window addSubview:myButton]; }   - (void)clickHandler { NSLog(@"You clicked button!"); }