9

私はUITableViewControllerを持っています。このコントローラーでは、UITextField を含むサブビュー UIView を追加します。UITextField がファーストレスポンダを取得したとき

テーブルのファーストレスポンダ ビューを設定するが、そのタイプ (セル/ヘッダー/フッター) がわからない

以下のようにコードします。

@interface UserAlbumListViewController (){
    NSString *newAlbumName;
    UITextField *albumNameField;
}

@end

-(void)addAlbumButtonPressed:(id)sender{
self.tableView.scrollEnabled = NO;
CGRect frame = self.view.frame;
UIView *opaqueView = [[UIView alloc] initWithFrame:frame];
opaqueView.tag = 1001;
opaqueView.backgroundColor = [UIColor colorWithWhite:0 alpha:0.5];


UIView *controllerView = [[UIView alloc] init];
controllerView.tag = 1002;
controllerView.backgroundColor = [UIColor whiteColor];
controllerView.frame = CGRectMake(10.0f, 60.0f, frame.size.width - 20.0f, 90.0f);
[opaqueView addSubview:controllerView];

albumNameField = [[UITextField alloc] init];
albumNameField.borderStyle = UITextBorderStyleRoundedRect; 
albumNameField.placeholder = NSLocalizedString(@"Album Name",nil);
albumNameField.keyboardType = UIKeyboardTypeDefault;
albumNameField.returnKeyType = UIReturnKeyDefault;
albumNameField.autocorrectionType = UITextAutocorrectionTypeNo;
albumNameField.autocapitalizationType = UITextAutocapitalizationTypeNone;
albumNameField.clearButtonMode = UITextFieldViewModeWhileEditing;
albumNameField.clearsOnBeginEditing = NO;
albumNameField.text = @"";
albumNameField.frame = CGRectMake(10.0f , 10.0f, controllerView.frame.size.width - 20.0f, 30.0f);
[albumNameField becomeFirstResponder];
[controllerView addSubview:albumNameField];


UIButton *_cancelButton =  [UIButton buttonWithType:UIButtonTypeRoundedRect];
_cancelButton.backgroundColor = [UIColor clearColor];
[_cancelButton setTitle:NSLocalizedString(@"Cancel",nil) forState:UIControlStateNormal];
_cancelButton.frame = CGRectMake( controllerView.frame.size.width - 90.0f,  albumNameField.frame.origin.y + albumNameField.frame.size.height + 10.0f, 80.0f, 30.0f);

[_cancelButton addTarget:self action:@selector(opaqueViewCancelButtonClicked:) forControlEvents:UIControlEventTouchDown];
[controllerView addSubview:_cancelButton];

UIButton *_OKButton =  [UIButton buttonWithType:UIButtonTypeRoundedRect];
_OKButton.backgroundColor = [UIColor clearColor];
[_OKButton setTitle:NSLocalizedString(@"OK",nil) forState:UIControlStateNormal];
_OKButton.frame = CGRectMake( _cancelButton.frame.origin.x - 90.f, _cancelButton.frame.origin.y, 80.0f, 30.0f);
[_OKButton addTarget:self action:@selector(opaqueViewOKButtonClicked:) forControlEvents:UIControlEventTouchDown];
[controllerView addSubview:_OKButton];

[self.view addSubview:opaqueView];

[controllerView release];
[opaqueView release];
}

この警告を回避するにはどうすればよいですか?

4

2 に答える 2

18

この警告は、opaqueView をテーブル ビューに直接追加したことを示しています。テーブル ビューは、インタラクティブなサブビューが tableHeaderView、tableFooterView、またはセル内に追加されることを想定しています。

問題のある行は[self.view addSubview:opaqueView];、 self.view がテーブルビューであるためです。

これを修正する方法はいくつかあります。ナビゲーション コントローラーを使用している場合は、opaqueView を含む新しいコントローラーをプッシュできます。テーブルビューの上に opaqueView を含むモーダルビューをポップアップできます。self.view がテーブルビューでないように構造を変更できます (これは大変な作業です)。


アップデート

この回答はちょっと忙しいので、更新を投稿します。Apple は、私が提案したソリューションとは異なるソリューションを使用していることに気付きました。

[self.view addSubview:opaqueView];サブビューをテーブル ビューに追加しようとする代わりに、サブビューを[self.view.window addSubview:opaqueView];テーブル ビューのウィンドウに直接追加することができます。ビューを使用しているため、境界とフレームが とは異なる場合があることに注意してくださいself.view

于 2012-05-26T14:07:04.000 に答える
1

NavigationController にプッシュされたビューが UIView ではなく UITableView のインスタンスであった場合、この「(セル/ヘッダー/フッター)」エラーが発生しました。次に、クラスの Xib エディターでキャンバスにビューを追加すると、最終的にテキストがさらにいくつかのビューを介してビューに追加されました。UI ビルダーを使用すると、ビューのスーパークラスとして UITableView を指定し、キャンバスにビューを配置できます。このビューに項目を追加すると、「テーブルのファーストレスポンダー ビューを設定していますが、そのタイプがわかりません」というメッセージが表示されます。 (セル/ヘッダー/フッター)".

于 2012-05-27T22:20:45.713 に答える