我試圖將方法alertViewShouldEnableFirstOtherButton中用戶輸入的第一個字母改爲大寫。一切正常的iOS 6中,但在iOS 5中,似乎我得到的無限循環(當我設置警報視圖的文本字段編程調用方法alertViewShouldEnableFirstOtherButton遞歸) 這是代碼:alertViewShouldEnableFirstOtherButton中的無限循環iOS5
- (BOOL)alertViewShouldEnableFirstOtherButton:(UIAlertView *)alertView{
NSString *inputText = [[alertView textFieldAtIndex:0] text];
if(inputText.length==0)return NO;
unichar firstChar=[[inputText capitalizedString] characterAtIndex:0];
NSString *capitalizedLetter= [NSString stringWithCharacters:&firstChar length:1];
NSString *str=[inputText stringByReplacingCharactersInRange:NSMakeRange(0, 1) withString:capitalizedLetter];
[[alertView textFieldAtIndex:0] setText:str];// setText calls again alertViewShouldEnableFirstOtherButton
return YES;
}