【发布时间】:2015-10-30 23:13:13
【问题描述】:
我正在尝试创建一个保存按钮,当用户在 TextView 和 TextField 中输入文本时,该按钮将启用。
我为按钮创建了一个名为“saveButton”的IBOutlet。
使用以下代码,保存按钮永远不会启用。
- (void) enableSaveButtonForQuote: (NSString *) quoteText author: (NSString *) authorText {
self.saveButton.enabled = (quoteText.length > 0 && authorText > 0);
}
- (BOOL)textView:(UITextView *)textView shouldChangeTextInRange:
(NSRange)range replacementText:(NSString *)text
{
NSString *changedString = [textView.testringByReplacingCharactersInRange:
range withString: text];
[self enableSaveButtonForQuote: changedString author:
self.authorTextField.text];
return YES;
}
- (BOOL)textField:(UITextField *)textField shouldChangeCharactersInRange:
(NSRange)range replacementString:(NSString *)string
{
NSString *changedString = [textField.text stringByReplacingCharactersInRange:
range withString: string];
[self enableSaveButtonForQuote:self.quoteTextView.text author:changedString];
return YES;
}
【问题讨论】:
-
是否曾经调用过
UITextViewDelegate或UITextFieldDelegate方法? -
是的,它们是 - 两个代表都在头文件中声明
-
enableSaveButtonForQuote:author:方法是否被调用过? -
你不要在 shouldchangechatracters 方法中简单地启用=yes
-
使用调试器。验证您希望调用的所有方法实际上都在调用。验证各种值是否具有您期望它们具有的值。然后使用相关详细信息更新您的问题。没有人可以回答您的问题,因为您还没有告诉我们发布的代码实际发生了什么。
标签: ios objective-c uinavigationbar