0

テンキーに次/完了ボタンを実装する必要があります。

以下のコードを使用しています。

しかし、キーボード ビューの選択中に例外が発生します。境界を超えたインデックス 1 [0...0]

これが私のコードです。

//doneButton initialisation
doneButton = [UIButton buttonWithType:UIButtonTypeCustom];
doneButton.frame = CGRectMake(0, 163, 106, 53);
doneButton.adjustsImageWhenHighlighted = NO;
[doneButton setImage:[UIImage imageNamed:@"DoneUp.png"] forState:UIControlStateNormal];
[doneButton setImage:[UIImage imageNamed:@"DoneDown.png"] forState:UIControlStateHighlighted];
[doneButton addTarget:self action:@selector(textFieldShouldReturn:) forControlEvents:UIControlEventTouchUpInside];


//the exception i am taking
else if(textField == cardNumberField)
{

    UIWindow* tempWindow = [[[UIApplication sharedApplication] windows] objectAtIndex:1];
    UIView* keyboard;
    for(int i=0; i<[tempWindow.subviews count]; i++) {
        keyboard = [tempWindow.subviews objectAtIndex:i];
        // keyboard view found; add the custom button to it
        if([[keyboard description] hasPrefix:@"<UIKeyboard"] == YES) {
            [keyboard addSubview:doneButton];
        }
    }

    [mainScrollView setContentSize:CGSizeMake(0, mainScrollView.contentSize.height+185)];

    [mainScrollView setContentOffset:CGPointMake(0, mainScrollView.frame.origin.y+185)];
}
4

1 に答える 1

1

この行はエラーにつながります: UIWindow* tempWindow = [[[UIApplication sharedApplication] windows] objectAtIndex:1];.

アプリケーションには常にoneウィンドウがあるためです。

更新: この投稿を参照してください。

于 2013-12-20T07:49:13.207 に答える