前几天我发布了一个问题,但我没有包含足够的代码,而且我遇到了另一个问题。我不确定我是否应该使用[[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:]: index 2 beyond bounds [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;
}