After selecting a cell and writing something in it, I would like to hit the return/next button on the keyboard and simply move to the next cell, that's what I am trying to achieve. But after placi开发者_开发问答ng a breakpoint on my method textfieldShouldReturn, I find that it does not get visited, even though I pressed on the return/next key. Can someone explain why?
Thank you.
What do you mean by cell. It will only call when you have UITextField in the cell and also set delegate to self.
UITextField *txt=[[UITextField alloc]initWithFrame:CellFrame];
text.tag=indexPath.row;
txt.delegate=self;
[cell.contentView addSubview:txt];
then it will definitely call textFieldShouldReturn method. on return click
@interface WordListTableController : UITableViewController <UITextFieldDelegate>
{
}
@end
// Customize the appearance of table view cells. - (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;
}
加载中,请稍侯......
精彩评论