0

UITableViewCell 内に UITextField があり、ユーザーが UITextField 内で入力を開始したことを検出したいと考えています。そのため、UITextFields デリゲートを設定しましたが、そのコードを実行すると、「テーブルのファーストレスポンダー ビューを設定していますが、そのタイプ (セル/ヘッダー/フッター) がわかりません」という警告が表示され、UITextField デリゲート メソッドが呼び出されません。 . UITextField メソッドを正しく呼び出すにはどうすればよいですか?

-(void)tableView:(id)view willDisplayCell:(UITableViewCell *)cell forRowAtIndexPath:(NSIndexPath *)indexPath {
    if ((indexPath.section == 0) && (indexPath.row == 3)) {
        UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(friendCellTapped)];
        [tap setNumberOfTapsRequired:1];
        [cell addGestureRecognizer:tap];
    }
    else if ((indexPath.section == 0) && (indexPath.row == 4)) {
        NSLog(@"im called");
        UITextField *tagBox = [[UITextField alloc] initWithFrame:CGRectMake(50, 6, 225, 25)];
        [tagBox setBorderStyle:UITextBorderStyleRoundedRect];
        [tagBox setReturnKeyType:UIReturnKeyDone];
        tagBox.delegate = self;
        [cell addSubview:tagBox];
    }
    else {
        %orig;
    }
}
4

1 に答える 1

0

UITextFieldクラスで変数を作成UIViewControllerし、UITableViewCellのテキストフィールドに設定することで、これを以前に行いましたtableView:cellForRowAtIndexPathUITextField次に、変数のデリゲートを に設定しviewDidAppear:ます。

このようなもの:

-(void)viewDidAppear:(BOOL)animated
{
    [super viewDidAppear:animated];

    self.theTextField.delegate = self;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
   //load custom cell

   self.theTextField = myCustomCell.cellTextField;

   return myCustomCell;
}

次に、UITextFieldDelegate メソッドが呼び出されます。

于 2013-07-31T20:15:05.613 に答える