我认为这很简单,但显然不是,至少不是我。我在UITextField
文件中声明了.h
并声明了其属性,以及IBAction
来清除字段中的文本。
IBOutlet UITextField *textField1;
@property(nonatomic, retain) UITextField *textField1;
-(IBAction)clearText:(id)sender
然后在我的实现文件(.m
)中,这就是我编写清除文本的方法。
-(IBAction)clearText:(id)sender {
textField1.text = NULL;
}
但是当我按下模拟器中的按钮时没有任何反应。为什么呢?
答案 0 :(得分:3)
你真的连接了插座吗?
另外,我建议使用nil
或@""
代替NULL
答案 1 :(得分:0)
这必须有效:
textField1.text = @"";
进一步检查textFiel1的outled是否已连接(XCode中的黑色填充圆圈)
添加日志语句到
-(IBAction)clearText:(id)sender {
NSLog(@"clearText");
textField1.text = @"";
}
查看是否被调用。
如果未调用,请同时检查clearText:(id)sender
的支出。