我創建了一個UIButton以編程方式向它添加了一個函數。它在運行時不響應。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];
}
}
Thanx提前...
有你在你的'checkError'嘗試的NSLog(...),看看它是越來越叫什麼名字? – bendytree 2013-03-27 22:28:17
[UIColor Gray]如何編譯? – danh 2013-03-27 22:29:22