先日質問を投稿しましたが、十分なコードが含まれておらず、さらに問題が発生しています。を使用する必要があるかどうかはわかりません[[UIApplication sharedApplication] windows]
が、修正後、先日、配列に正しい量の値がないようにすることをお勧めしました。
誰かが私がどこで間違っているのか、そしてそれが正しいかどうかをアドバイス/見せてもらえます[[UIApplication sharedApplication] windows]
か?
- (void) addDoneToKeyboard {
doneButton.hidden = NO;
//Add a button to the top, above all windows
NSArray *allWindows = [[UIApplication sharedApplication] windows];
NSUInteger topWindowIndex = [allWindows count];// fix - 1;
UIWindow *topWindow = [allWindows objectAtIndex:topWindowIndex]; //SIGABRT
キャッチされなかった例外'NSRangeException'が原因でアプリを終了しています。理由:'-[NSMutableArray objectAtIndex:]:インデックス2が境界を超えています[0 .. 1] '
// check if top window is of keypad or else
NSString *topViewClassName = [NSString stringWithFormat:@"%@",
[topWindow class]];
while (![topViewClassName isEqualToString:@"UITextEffectsWindow"] ) {
--topWindowIndex;
if(topWindowIndex < 1) // fix 0
break;
topWindow = [allWindows objectAtIndex:topWindowIndex];
topViewClassName = [NSString stringWithFormat:@"%@", [topWindow class]];
}
//
if(topWindowIndex < 1) { // fix 0
topWindowIndex = [allWindows count] - 1;
topWindow = [allWindows objectAtIndex:topWindowIndex];
}
if (doneButton.superview)
[doneButton removeFromSuperview];
[topWindow addSubview:doneButton];
if (!doneButtonShownRecently) {
[UIView beginAnimations:nil context:nil];
[UIView setAnimationBeginsFromCurrentState:YES];
[UIView setAnimationDuration:SLIDE_IN_ANIMATION_DURATION];
[UIView setAnimationCurve:UIViewAnimationCurveEaseInOut];
doneButton.frame = CGRectMake(0, 480-53,
doneButton.frame.size.width, 53);
[UIView commitAnimations];
} else {
doneButton.frame = CGRectMake(0, 427,
doneButton.frame.size.width, 53);
}
doneButtonShown = YES;
}