我正在尝试创建一个按钮,一旦点击它将显示另一个 UIView 的弹出窗口。为了测试这一点,我在 viewDidLoad 部分中有以下代码:
- (void)viewDidLoad
{
[super viewDidLoad];
self.hard1 = [UIButton buttonWithType:UIButtonTypeCustom];
[self.hard1 setFrame:CGRectMake(884, 524, 105, 60)]; // set the x,y,width and height based on your specs
UIImage *buttonImage = [UIImage imageNamed:@"green.jpg"];
hard1.layer.cornerRadius = 10;
hard1.clipsToBounds = YES;
[hard1 addTarget: self
action: @selector(buttonClicked:)
forControlEvents: UIControlEventTouchUpInside];
[self.hard1 setImage:buttonImage forState:UIControlStateNormal];
[self.view addSubview:self.hard1];
}
再往下:
- (IBAction) buttonClicked: (id)sender
{
NSLog(@"Tap");
}
但是,当我按下按钮时,控制台不会记录“Tap”。有任何想法吗?