運行此:爲什麼valueForKey:在UITextField上引發UITextInputTraits屬性的異常?
@try
{
NSLog(@"1. autocapitalizationType = %d", [self.textField autocapitalizationType]);
NSLog(@"2. autocapitalizationType = %@", [self.textField valueForKey:@"autocapitalizationType"]);
}
@catch (NSException *exception)
{
NSLog(@"3. %@", exception);
}
輸出這樣的:
1. autocapitalizationType = 0
3. [<UITextField 0x6c15df0> valueForUndefinedKey:]: this class is not key value coding-compliant for the key autocapitalizationType.
我期待:
1. autocapitalizationType = 0
2. autocapitalizationType = 0
此例外只屬於UITextInputTraits
協議的一部分性質發生。 常規UITextField
這樣的屬性可以通過valueForKey:
訪問clearButtonMode
。
那麼,爲什麼你不能訪問UITextInputTraits
屬性與鍵值編碼?
可能由於實施細節。您應該向Apple提交[bug報告](http://bugreport.apple.com)。 –