0

选择 acell并在其中写入内容后,我想点击键盘上的 return/next 按钮并简单地移动到 next cell,这就是我想要实现的。但是breakpoint在我的方法上放置 a 之后textfieldShouldReturn,我发现它没有被访问,即使我按下了 return/next 键。有人可以解释为什么吗?

谢谢你。

4

2 回答 2

0

你是什​​么意思cell。它只会在你有UITextField并且cell也设置为时delegate调用self

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

[cell.contentView addSubview:txt];

那么它肯定会调用textFieldShouldReturn方法。返回点击

于 2011-09-23T04:04:30.517 回答
0
@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;
}
于 2011-09-24T02:55:06.613 回答