嗨,我是一个初学者编程,并且一直被困在这个任务很长时间,似乎没有任何地方。当textfields为空时禁用按钮
基本上,我有几个文本域,当用户按下按钮时在不同的页面上生成输入信息。我希望该按钮被禁用,直到所有文本字段都充满了信息。
到目前为止,我有这样的:
- (void)textFieldDidEndEditing:(UITextField *)textField
{
// make sure all fields are have something in them
if ((textfbookauthor.text.length > 0)&& (textfbookedition.text.length > 0)&& (textfbookplace.text.length > 0)&& (textfbookpublisher.text.length > 0) && (textfbookpublisher.text.length > 0) && (textfbooktitle.text.length > 0) && (textfbookyear.text.length > 0)) {
self.submitButton.enabled = YES;
}
else {
self.submitButton.enabled = NO;
}
}
问题是“提交按钮”快到了一个错误,哪些需要在它的地方去? 我试图把我的按钮'bookbutton',而不是它的工作。
这是我的功能为“生成”按钮
-(IBAction)bookbutton:(id)sender;
{
NSString* combinedString = [NSString stringWithFormat:
@"%@ %@ %@.%@.%@:%@.",
textfbookauthor.text,
textfbookyear.text,
textfbooktitle.text,
textfbookedition.text,
textfbookplace.text,
textfbookpublisher.text];
BookGenerate*bookg = [[BookGenerate alloc] init];
bookg.message = combinedString;
bookg.modalTransitionStyle = UIModalTransitionStyleFlipHorizontal;
[self presentModalViewController:bookg animated:YES];
[BookGenerate release];
}
如果有人知道我怎么可以让它工作或我需要添加,请帮助什么。
在此先感谢
谢谢你为我提供这个我现在会尝试 – Ayub
好!感谢这个答案。如果使用UITextView,请尝试[this](http://stackoverflow.com/a/35674334/3411787)。 –