我以编程方式创建了一个 UIButton 并向其添加了一个功能。它在运行时不响应。
scrollViewFrame = CGRectMake(10, 110, 300, 40);
loginBut = [UIButton buttonWithType:UIButtonTypeRoundedRect];
loginBut.frame = scrollViewFrame;
loginBut.backgroundColor = [UIColor whiteColor];
loginBut.titleLabel.font = [UIFont fontWithName:@"Trebuchet MS" size:33];
[loginBut setTitleColor:[UIColor Gray] forState:UIControlStateNormal];
[loginBut setTitle:@"Login" forState:UIControlStateNormal];
[loginBut setContentHorizontalAlignment:UIControlContentHorizontalAlignmentLeft];
[loginBut addTarget:self
action:@selector(checkError)
forControlEvents:UIControlEventTouchUpInside];
self.loginBut = loginBut;
[self.view addSubview:loginBut];
那个行动:
- (void)checkError {
if ([dispName.text isEqualToString:@""]&&[pw.text isEqualToString:@""]) {
UIAlertView *alertFailed = [[UIAlertView alloc]initWithTitle:@"\nError" message:@"1. Display Name missing.\n2. Password missing." delegate:self cancelButtonTitle:nil otherButtonTitles:nil, nil];
[alertFailed show];
}
}
提前谢谢...