【发布时间】:2013-09-05 22:08:10
【问题描述】:
我正在开发一个 iOS 应用程序,其中只有在填写了所有 UITextFields 之后才启用按钮(即每个字符中至少有一个字符)。每个UITextField 都位于UITableView 内部的自定义UITableViewCell 中。一旦用户在每个UITextField 中输入了一个值,我就需要启用该按钮。在我的 viewDidLoad 方法中,我禁用了按钮,如下所示:
[_doneButton setEnabled:NO];
然后我有以下方法:
- (BOOL)textField:(UITextField *)textField shouldChangeCharactersInRange:(NSRange)range replacementString:(NSString *)string {
for (int i = 0; i < [self.table numberOfSections]; i++) {
NSInteger rows = [self.table numberOfRowsInSection:i];
for (int row = 0; row < rows; row++) {
NSIndexPath *indexPath = [NSIndexPath indexPathForRow:row inSection:i];
SimpleTableCell *cell = (SimpleTableCell *)[self.table cellForRowAtIndexPath:indexPath];
for (UIView *subView in cell.subviews) {
if ([subView isKindOfClass:[UITextField class]]) {
//Does not come to this point
UITextField *txtField = (UITextField *)subView;
if([[txtField text] length] > 0) {
//Enable button and bold title
[_doneButton setEnabled:YES];
[_doneButton.titleLabel setFont:[UIFont boldSystemFontOfSize:28]];
}
else {
[_doneButton setEnabled:NO];
}
}
}
}
}
return YES;
}
不幸的是,我的代码没有进入“if”子句,在该子句中我检查自定义单元格是否具有UITextField 类型的子视图,因此,该按钮永远不会启用。作为记录,“SimpleTableCell”是我创建的自定义UITableViewCell 类的名称。我的代码似乎是正确的,但我不知道为什么它不能正常运行。谁能看到我做错了什么?
【问题讨论】:
标签: ios uitableview uitextfield uitextfielddelegate