Just come cross a strange bug in devices with 32 bit architecture, below is the code:
- (void)textViewDidChange:(UITextView *)textView {
self.button.enabled = textView.text.length;
}
So whenever I paste some text whose length is not 1 into the textView, (this is to imitate the behaviour of a third-party keyboard Sogou ), the button will not be enabled.
You can use this Demo to reproduce the bug.
I've read related posts, like Assigning NSUInteger to BOOL conceptual understanding , but this case is different.
Please tell me why it does not work here.
Don't think of it as a bug. Think of it as your code being wrong. This line is horrible:
self.button.enabled = textView.text.length;
You are trying to misuse a number as a BOOL. You are thus assuming that any non-zero number is the same as YES
. That is a false assumption. Stop writing code like that. Write it like this:
self.button.enabled = (textView.text.length > 0);
That way, the BOOL really is a BOOL.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.