Мое текстовое поле UITableViewCell и мое textfieldShouldReturn не видят друг друга - PullRequest
0 голосов
/ 23 сентября 2011

После выбора cell и записи чего-либо в него я бы хотел нажать кнопку возврата / перехода на клавиатуре и просто перейти к следующему cell, вот чего я пытаюсь достичь. Но после размещения breakpoint в моем методе textfieldShouldReturn я обнаружил, что он не посещается, хотя я нажал клавишу возврата / следующего. Может кто-нибудь объяснить, почему?

Спасибо.

Ответы [ 2 ]

0 голосов
/ 24 сентября 2011
@interface WordListTableController : UITableViewController <UITextFieldDelegate>
{
}

@end

// Настройка внешнего вида ячеек табличного представления. - (UITableViewCell *) tableView: (UITableView *) tableView cellForRowAtIndexPath: (NSIndexPath *) indexPath {

    static NSString *CellIdentifier = @"Cell";

    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
    if (cell == nil) {
        cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault     reuseIdentifier:CellIdentifier] autorelease];
}

// Configure the cell...
UITextField *FirstField = [[UITextField alloc] initWithFrame:CGRectMake(10, 10, 130, 25)];
FirstField.delegate = self;
[FirstField setTag:indexPath.row];
FirstField.returnKeyType = UIReturnKeyNext;
[cell.contentView addSubview:FirstField];
[FirstField release];


return cell;
}


// Handle any actions, after the return/next/done button is pressed
- (BOOL)textfieldShouldReturn:(UITextField *)textfield 
{
[textfield resignFirstResponder];

return NO;
}
0 голосов
/ 23 сентября 2011

Что вы подразумеваете под cell. Он будет вызываться только тогда, когда у вас есть UITextField в cell, а также для delegate установлено self.

UITextField *txt=[[UITextField alloc]initWithFrame:CellFrame];
text.tag=indexPath.row;
txt.delegate=self;

[cell.contentView addSubview:txt];

тогда он обязательно вызовет textFieldShouldReturn метод. при возврате нажмите

...