UIButton没有响应
我创建了一个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提前...
只写了的NSLog()的方法- (void)checkError
里面。如果打印出来,那么您的if
条件出错了。
否则只是尝试,
[self.view bringSubViewToFront:loginBut];
loginBut.userIntractionEnabled = YES;
([dispName.text isEqualToString:@ “”] & & [pw.text isEqualToString:@” “])
也许这些测试只是失败。例如,也许dispName.text
是零。这不等于空字符串。
这个想法是,如果没有任何关键字在dispName和pw文本字段中,它会提示一个提示。我猜它不是'isEqualToString'?它应该是什么? – 2013-03-27 22:35:09
为什么不使用NSLog或在调试器中暂停以检查它们的值是什么时候?你似乎没有做任何测试,记录或调试。你不必*猜*你的代码在做什么,你知道!你不应该这样做。 – matt 2013-03-27 23:10:04
,看看是否按钮最初响应if语句前加上
NSLog("checkError");
的方法
- (void)checkError;
有你在你的'checkError'尝试的NSLog(...),看看它是越来越叫什么名字? – bendytree 2013-03-27 22:28:17
[UIColor Gray]如何编译? – danh 2013-03-27 22:29:22