- (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!"); }