I have this view:
and these implementations:
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
static NSString *CellIdentifier = #"Cell";
UITableViewCell *cell = [self.tableLogin dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {
cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault
reuseIdentifier:CellIdentifier] autorelease];
cell.accessoryType = UITableViewCellAccessoryNone;
cell.selectionStyle = UITableViewCellSelectionStyleNone;
if ([indexPath section] == 0) {
UITextField *textfield = [[UITextField alloc] initWithFrame:CGRectMake(110, 10, 165, 30)];
textfield.adjustsFontSizeToFitWidth = YES;
textfield.textColor = [UIColor blackColor];
textfield.backgroundColor = [UIColor whiteColor];
textfield.autocorrectionType = UITextAutocorrectionTypeNo;
textfield.autocapitalizationType = UITextAutocapitalizationTypeNone;
textfield.textAlignment = UITextAlignmentLeft;
textfield.clearButtonMode = UITextFieldViewModeNever;
textfield.delegate = self;
if ([indexPath row] == 0) {
textfield.tag = 0;
textfield.placeholder = #"your username";
textfield.keyboardType = UIKeyboardTypeDefault;
textfield.returnKeyType = UIReturnKeyNext;
}
else {
textfield.tag = 1;
textfield.placeholder = #"required";
textfield.keyboardType = UIKeyboardTypeDefault;
textfield.returnKeyType = UIReturnKeyDone;
textfield.secureTextEntry = YES;
}
[textfield setEnabled:YES];
[cell addSubview:textfield];
[textfield release];
}
}
if ([indexPath section] == 0) {
if ([indexPath row] == 0) {
cell.textLabel.text = #"Email";
}
else {
cell.textLabel.text = #"Password";
}
}
return cell;
}
- (BOOL)textFieldShouldReturn:(UITextField *)textField
{
switch (textField.tag) {
case 0:
self.username = textField.text;
break;
case 1:
self.password = textField.text;
break;
}
return true;
}
When the user click Login button without tap "Done" for close the keyboard it doesn't save the field values. How can I tricky-fix this?
Two options:
Keep a reference to both textfields and pull their text values in the "Done" button's action method.
Alternatively, register for the UITextFieldTextDidChangeNotification and capture input as it happens.
You can use - (void)textFieldDidEndEditing:(UITextField *)textField and save your values there, in addition to hitting the return key.
Related
I have a UITableView that I used for username/password enter.
But I have problem to get values when I click on button.
This is how I make table:
- (UITableViewCell *)tableView:(UITableView *)table cellForRowAtIndexPath:(NSIndexPath *)indexPath {
static NSString *kCellIdentifier = #"Cell";
UITableViewCell *cell = [self.tableView dequeueReusableCellWithIdentifier:kCellIdentifier];
if (cell == nil) {
cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault
reuseIdentifier:kCellIdentifier];
cell.accessoryType = UITableViewCellAccessoryNone;
if ([indexPath section] == 0) {
UITextField *playerTextField = [[UITextField alloc] initWithFrame:CGRectMake(110, 10, 185, 30)];
playerTextField.adjustsFontSizeToFitWidth = YES;
playerTextField.textColor = [UIColor blackColor];
if ([indexPath row] == 0) {
playerTextField.placeholder = #"example#gmail.com";
playerTextField.keyboardType = UIKeyboardTypeEmailAddress;
playerTextField.returnKeyType = UIReturnKeyNext;
}
else {
playerTextField.placeholder = #"Required";
playerTextField.keyboardType = UIKeyboardTypeDefault;
playerTextField.returnKeyType = UIReturnKeyDone;
playerTextField.secureTextEntry = YES;
}
playerTextField.backgroundColor = [UIColor whiteColor];
playerTextField.autocorrectionType = UITextAutocorrectionTypeNo;
playerTextField.autocapitalizationType = UITextAutocapitalizationTypeNone;
playerTextField.textAlignment = NSTextAlignmentLeft;
playerTextField.tag = 0;
playerTextField.clearButtonMode = UITextFieldViewModeNever;
[playerTextField setEnabled: YES];
playerTextField.backgroundColor = [UIColor clearColor];
cell.selectionStyle = UITableViewCellSelectionStyleNone;
[cell addSubview:playerTextField];
}
}
if ([indexPath section] == 0) { // Email & Password Section
if ([indexPath row] == 0) { // Email
cell.textLabel.text = #"Email";
}
else {
cell.textLabel.text = #"Password";
}
}
return cell;
}
And this is what I have tried in button tap:
...
for (UITableViewCell* aCell in [self.tableView visibleCells] ) {
UITextField* aField = (UITextField *)[aCell viewWithTag:0];
NSLog(aField.text);
}
..
This prints me just: Email Password (labels not data that I entered).
How to get entered values here?
All views default their tag to 0. Because of this, [aCell viewWithTag: 0] is returning the first view with tag zero - in this case the cell's textLabel - which is a UILabel that also responds to .text. If you set the tags in your cellForRowAtIndexPath: to something other than zero it should start working for you.
In that case you can give the tag to textfield like playerTextField.tag = 115 and you can get view by tag like UITextField *aField = (UITextField *)[aCell viewWithTag:115]; and display NSLog(#"text:%#",aField.text);
I have a UITableView that I use as a form for registration I want when I click on first text input on the keyboard to have NEXT button. I have tried something but It always show DONE button and on it's tap it moves me to last text input.
- (UITableViewCell *)tableView:(UITableView *)table cellForRowAtIndexPath:(NSIndexPath *)indexPath {
static NSString *kCellIdentifier = #"Cell";
UITableViewCell *cell = [self.tableView dequeueReusableCellWithIdentifier:kCellIdentifier];
if (cell == nil) {
cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault
reuseIdentifier:kCellIdentifier];
cell.accessoryType = UITableViewCellAccessoryNone;
if ([indexPath section] == 0) {
playerTextField = [[UITextField alloc] initWithFrame:CGRectMake(110, 10, 185, 30)];
playerTextField.adjustsFontSizeToFitWidth = YES;
playerTextField.textColor = [UIColor blackColor];
if ([indexPath row] == 0) {
playerTextField.placeholder = #"Required";
playerTextField.keyboardType = UIKeyboardTypeDefault;
playerTextField.returnKeyType = UIReturnKeyDone;
playerTextField.tag = 3;
}
else if([indexPath row] == 1){
playerTextField.placeholder = #"Required";
playerTextField.keyboardType = UIKeyboardTypeDefault;
playerTextField.returnKeyType = UIReturnKeyDone;
playerTextField.tag = 4;
}
else if([indexPath row] == 2){
playerTextField.placeholder = #"example#gmail.com";
playerTextField.keyboardType = UIKeyboardTypeEmailAddress;
playerTextField.returnKeyType = UIReturnKeyNext;
playerTextField.tag = 1;
}
else {
playerTextField.placeholder = #"password";
playerTextField.keyboardType = UIKeyboardTypeDefault;
playerTextField.returnKeyType = UIReturnKeyDone;
playerTextField.secureTextEntry = YES;
playerTextField.tag = 2;
}
playerTextField.backgroundColor = [UIColor whiteColor];
playerTextField.autocorrectionType = UITextAutocorrectionTypeNo;
playerTextField.autocapitalizationType = UITextAutocapitalizationTypeNone;
playerTextField.textAlignment = NSTextAlignmentLeft;
playerTextField.delegate = self;
playerTextField.clearButtonMode = UITextFieldViewModeNever;
[playerTextField setEnabled: YES];
playerTextField.backgroundColor = [UIColor clearColor];
cell.selectionStyle = UITableViewCellSelectionStyleNone;
[cell addSubview:playerTextField];
}
}
if ([indexPath section] == 0) { // Email & Password Section
if ([indexPath row] == 0) { // Email
cell.textLabel.text = #"First Name";
}
else if ([indexPath row] == 1) { // Email
cell.textLabel.text = #"Last Name";
}
else if([indexPath row] == 2){
cell.textLabel.text = #"Email";
}
else {
cell.textLabel.text = #"Password";
}
}
return cell;
}
...
-(BOOL) textFieldShouldReturn:(UITextField *)textField{
if(textField.tag == 3) {
[playerTextField becomeFirstResponder];
}else if(textField.tag == 4) {
[playerTextField becomeFirstResponder];
}else if(textField.tag == 1) {
[playerTextField becomeFirstResponder];
} else if(textField.tag == 2) {
[playerTextField resignFirstResponder];
}
return NO;
}
change this
playerTextField.returnKeyType = UIReturnKeyDone;
to
playerTextField.returnKeyType = UIReturnKeyNext;
rest of the code in the link->"in comment" to move to next text field
I've created a custom cell with a textField but I'm not able to retrieve its value.
In my tableView, there are 3 of these custom cells, together with other default cells.
When I try this:
NSString *string = customCell.textField.text;
I always get a null value...
This is my code:
TextFieldCell.m
#import "TextFieldCell.h"
#implementation TextFieldCell
#synthesize label;
#synthesize textField;
- (id)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
if (self)
{
label = [[UILabel alloc] initWithFrame:CGRectZero];
label.backgroundColor = [UIColor clearColor];
label.textAlignment = UITextAlignmentRight;
label.textColor = [UIColor blackColor];
label.font = [UIFont boldSystemFontOfSize:16.0];
label.adjustsFontSizeToFitWidth = YES;
label.baselineAdjustment = UIBaselineAdjustmentNone;
label.numberOfLines = 20;
[self.contentView addSubview:label];
textField = [[UITextField alloc] initWithFrame:CGRectZero];
textField.contentVerticalAlignment = UIControlContentVerticalAlignmentCenter;
textField.backgroundColor = [UIColor clearColor];
textField.font = [UIFont boldSystemFontOfSize:16.0];
textField.delegate = self;
textField.returnKeyType = UIReturnKeyDone;
[self.contentView addSubview:textField];
}
return self;
}
-(void)layoutSubviews
{
[super layoutSubviews];
CGRect r = CGRectInset(self.contentView.bounds, 8, 8);
CGRect r1 = CGRectInset(self.contentView.bounds, 8, 8);
if (label.text != nil)
{
r.size = CGSizeMake(12, 27);
label.frame = r;
r1.origin.x += self.label.frame.size.width + 6;
r1.size.width -= self.label.frame.size.width + 6;
textField.frame = r1;
}
else
{
textField.frame = r;
}
}
-(BOOL)textFieldShouldReturn:(UITextField *)aTextField
{
[textField resignFirstResponder];
return NO;
}
- (void)setSelected:(BOOL)selected animated:(BOOL)animated
{
[super setSelected:selected animated:animated];
}
#end
Table View Data Source
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
if (indexPath.section == 0)
{
if (indexPath.row == 0)
{
return [self textFieldCellForTableView:tableView atIndexPath:indexPath];
}
else if (indexPath.row == 1)
{
return [self textFieldCellForTableView:tableView atIndexPath:indexPath];
}
else
{
return [self defaultCellForTableView:tableView atIndexPath:indexPath];
}
}
else if (indexPath.section == 1)
{
if (indexPath.row == 0)
{
return [self textFieldCellForTableView:tableView atIndexPath:indexPath];
}
else
{
return [self defaultCellForTableView:tableView atIndexPath:indexPath];
}
}
else if (indexPath.section == 2)
{
return [self defaultCellForTableView:tableView atIndexPath:indexPath];
}
else
{
return [self chooseFotoCellForTableView:tableView atIndexPath:indexPath];
}
}
-(TextFieldCell *)textFieldCellForTableView:(UITableView *)tableView atIndexPath:(NSIndexPath *)indexPath
{
static NSString *TextFieldCellIdentifier = #"TextFieldCellIdentifier";
TextFieldCell *cell = [tableView dequeueReusableCellWithIdentifier:TextFieldCellIdentifier];
if (cell == nil)
{
cell = [[[TextFieldCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:TextFieldCellIdentifier] autorelease];
cell.selectionStyle = UITableViewCellSelectionStyleNone;
}
if (indexPath.section == 0)
{
if (indexPath.row == 0)
{
cell.label.text = nil;
cell.textField.placeholder = NSLocalizedString(#"Nome", #"");
}
else
{
cell.label.text = [[NSLocale currentLocale] objectForKey:NSLocaleCurrencySymbol];
cell.textField.placeholder = NSLocalizedString(#"Costo", #"");
}
}
else
{
cell.label.text = nil;
cell.textField.placeholder = NSLocalizedString(#"URL", #"");
}
return cell;
}
Code To Retrieve TextField Value
TextFieldCell *nomeCell = (TextFieldCell *)[self tableView:self.tableView cellForRowAtIndexPath:[NSIndexPath indexPathForRow:0 inSection:0]];
TextFieldCell *costoCell = (TextFieldCell *)[self tableView:self.tableView cellForRowAtIndexPath:[NSIndexPath indexPathForRow:1 inSection:0]];
TextFieldCell *linkCell = (TextFieldCell *)[self tableView:self.tableView cellForRowAtIndexPath:[NSIndexPath indexPathForRow:0 inSection:1]];
NSLog(#"nomeCell textField = %#", nomeCell.textField.text);
NSLog(#"costoCell textField = %#", costoCell.textField.text);
NSLog(#"linkCell textField = %#", linkCell.textField.text);
I tried to log nomeCell, costoCell and linkCell and they are correctly allocated and initialized and I'm not using ARC here...
Can anyone help me?
Thank you so much!
I assume that you have actually entered some text in the text field by the time you are trying to retrieve the values, and you are retrieving the values to update your data model rather than relying on the table view / cells to store your data?
Don't obtain the current cell by calling your table view controller's tableView:cellForRowAtIndexPath:. This should only be called by the table view when it needs a new cell.
Call the cellForRowAtIndexPath: method on the table view directly. Instead of this:
TextFieldCell *nomeCell = (TextFieldCell *)[self tableView:self.tableView cellForRowAtIndexPath:[NSIndexPath indexPathForRow:0 inSection:0]];
Do this:
TextFieldCell *nomeCell = (TextFieldCell *)[self.tableView cellForRowAtIndexPath:[NSIndexPath indexPathForRow:0 inSection:0]];
You are assigning text to placeholder property and you are logging textField.text.
textField = [[UITextField alloc] initWithFrame:CGRectZero];
textField.contentVerticalAlignment = UIControlContentVerticalAlignmentCenter;
textField.backgroundColor = [UIColor clearColor];
textField.font = [UIFont boldSystemFontOfSize:16.0];
textField.delegate = self;
//added
textField.tag = 101;
textField.returnKeyType = UIReturnKeyDone;
[self.contentView addSubview:textField];
Code To Retrieve TextField Value:
//fetch cell for which you want to get textfield then,
TextFieldCell *nomeCell = (TextFieldCell *)[cell.contentView viewWithTag:101];
How to put a UITextField inside of a UITableViewCell (grouped)? I want a user to be able to edit it.
Add the UITextField as an subview of the UITableViewCell's contentView:
[mycell.contentView addSubview:view];
Apple's own UICatalog demo application has an example of placing UITextFields in Grouped UITableView Cells: http://developer.apple.com/iphone/library/samplecode/UICatalog/index.html
Check the contents of TextFieldController.m
Plus there's lots of other great code there for working with UIKit Objects.
This is how I've implemented it into my application, however you'll obviously need to change a few things. Hope this helps.
- (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.
//adding all the UITextField's to the UITableViewCell is a pain in the ass. Pretty sure this is correct though.
if ([indexPath section] == 0) {
tUser = [[UITextField alloc] initWithFrame:CGRectMake(110, 10, 185, 30)];
tUser.adjustsFontSizeToFitWidth = YES;
tUser.textColor = [UIColor blackColor];
tPass = [[UITextField alloc] initWithFrame:CGRectMake(110, 10, 185, 30)];
tPass.adjustsFontSizeToFitWidth = YES;
tPass.textColor = [UIColor blackColor];
if ([indexPath section] == 0) {
if ([indexPath row] == 0) {
tUser.placeholder = #"#JohnAppleseed";
tUser.keyboardType = UIKeyboardTypeEmailAddress;
tUser.returnKeyType = UIReturnKeyNext;
}
if ([indexPath row] == 1) {
tPass.placeholder = #"Required";
tPass.keyboardType = UIKeyboardTypeDefault;
tPass.returnKeyType = UIReturnKeyDone;
tPass.secureTextEntry = YES;
}
}
tUser.backgroundColor = [UIColor whiteColor];
tUser.autocorrectionType = UITextAutocorrectionTypeNo;
tUser.autocapitalizationType = UITextAutocapitalizationTypeNone;
tUser.textAlignment = UITextAlignmentLeft;
tPass.backgroundColor = [UIColor whiteColor];
tPass.autocorrectionType = UITextAutocorrectionTypeNo;
tPass.autocapitalizationType = UITextAutocapitalizationTypeNone;
tPass.textAlignment = UITextAlignmentLeft;
tUser.clearButtonMode = UITextFieldViewModeNever;
tPass.clearButtonMode = UITextFieldViewModeNever;
[tUser setEnabled:YES];
[tPass setEnabled:YES];
//[tUser release];
//[tPass release];
}
if ([indexPath section] == 0) { // Email & Password Section
if ([indexPath row] == 0) { // Email
cell.textLabel.text = #"Username";
[cell addSubview:tUser];
[tUser setText:[[NSUserDefaults standardUserDefaults] objectForKey:#"twitter_name_preference"]];
}
else {
cell.textLabel.text = #"Password";
[cell addSubview:tPass];
[tPass setText:[[NSUserDefaults standardUserDefaults] objectForKey:#"twitter_pass_preference"]];
}
}
return cell; }
Hope it helps.
I have a TableViewController that is using a grouped Style and has two(2) sections. The first section has 4 rows and the second section has 3 rows. I have placed a UILabel and a UITextField in each cell, and have a custom method(textFieldDone:) to handle the cursor movement to the next text field when the return key is press.
This works fine and dandy if there is only one section, but I have two :( and yes I need two:)
so I started codin' up an answer, but got results that just don't work, I did notice during my debugging that cell Identifier (I use Two) is only showing the one (in the debug consol) and it's the first one only (Generic Cell).
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
UITableViewCell *cell = nil;
switch (indexPath.section)
{
case AUTO_DETAILS:
{
static NSString *cellID = #"GenericCell";
cell = [tableView dequeueReusableCellWithIdentifier:cellID];
if (cell == nil)
{
cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleValue2
reuseIdentifier:cellID] autorelease];
UILabel *label = [[UILabel alloc] initWithFrame:CGRectMake(10, 10, 75, 25)];
label.tag = kLabelTag;
label.font = [UIFont boldSystemFontOfSize:14];
label.textAlignment = UITextAlignmentRight;
[cell.contentView addSubview:label];
[label release];
UITextField *textField = [[UITextField alloc] initWithFrame:CGRectMake(90, 12, 200, 25)];
textField.clearsOnBeginEditing = NO;
[textField setDelegate:self];
[textField addTarget:self action:#selector(topTextFieldDone:) forControlEvents:UIControlEventEditingDidEndOnExit];
[cell.contentView addSubview:textField];
}
NSInteger row = [indexPath row];
UILabel *label = (UILabel *)[cell viewWithTag:kLabelTag];
UITextField *textField = nil;
for (UIView *oneView in cell.contentView.subviews)
{
if ([oneView isMemberOfClass:[UITextField class]])
textField = (UITextField *)oneView;
}
label.text = [topCellLabels objectAtIndex:row];
NSNumber *rowAsNum = [[NSNumber alloc] initWithInt:row];
switch (row)
{
case kMakeRowIndex:
if ([[tempValues allKeys] containsObject:rowAsNum])
textField.text = [tempValues objectForKey:rowAsNum];
else
textField.text = automobile.make;
break;
case kModelRowIndex:
if ([[tempValues allKeys] containsObject:rowAsNum])
textField.text = [tempValues objectForKey:rowAsNum];
else
textField.text = automobile.model;
break;
case kYearRowIndex:
if ([[tempValues allKeys] containsObject:rowAsNum])
textField.text = [tempValues objectForKey:rowAsNum];
else
textField.text = automobile.year;
break;
case kNotesRowIndex:
if ([[tempValues allKeys] containsObject:rowAsNum])
textField.text = [tempValues objectForKey:rowAsNum];
else
textField.text = automobile.notes;
break;
default:
break;
}
if (textFieldBeingEdited == textField)
{
textFieldBeingEdited = nil;
}
textField.tag = row;
[rowAsNum release];
break;
}
case AUTO_REGISTRATION:
{
static NSString *AutoEditCellID = #"AutoEditCellID";
cell = [tableView dequeueReusableCellWithIdentifier:AutoEditCellID];
if (cell == nil)
{
cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleValue2
reuseIdentifier:AutoEditCellID] autorelease];
UILabel *label = [[UILabel alloc] initWithFrame:CGRectMake(10, 10, 75, 25)];
label.tag = kLabelTag;
label.font = [UIFont boldSystemFontOfSize:14];
label.textAlignment = UITextAlignmentRight;
[cell.contentView addSubview:label];
[label release];
UITextField *textField = [[UITextField alloc] initWithFrame:CGRectMake(90, 12, 200, 25)];
textField.clearsOnBeginEditing = NO;
[textField setDelegate:self];
[textField addTarget:self action:#selector(bottomTextFieldDone:) forControlEvents:UIControlEventEditingDidEndOnExit];
[cell.contentView addSubview:textField];
}
NSInteger row = [indexPath row];
UILabel *label = (UILabel *)[cell viewWithTag:kLabelTag];
UITextField *textField = nil;
for (UIView *oneView in cell.contentView.subviews)
{
if ([oneView isMemberOfClass:[UITextField class]])
textField = (UITextField *)oneView;
}
label.text = [bottomCellLabels objectAtIndex:row];
NSNumber *rowAsNum = [[NSNumber alloc] initWithInt:row];
switch (row)
{
case 0:
if ([[tempValues allKeys] containsObject:rowAsNum])
textField.text = [tempValues objectForKey:rowAsNum];
else
textField.text = automobile.vinNumber;
break;
case 1:
if ([[tempValues allKeys] containsObject:rowAsNum])
textField.text = [tempValues objectForKey:rowAsNum];
else
textField.text = automobile.policyNumber;
break;
case 2:
if ([[tempValues allKeys] containsObject:rowAsNum])
textField.text = [tempValues objectForKey:rowAsNum];
else
textField.text = automobile.licensePlate;
break;
default:
break;
}
if (textFieldBeingEdited == textField)
{
textFieldBeingEdited = nil;
}
textField.tag = row;
[rowAsNum release];
break;
}
default:
break;
}
return cell;
}
Now remember that the first section is working fine and the code for that method is this:
-(IBAction)topTextFieldDone:(id)sender
{
UITableViewCell *cell = (UITableViewCell *)[[sender superview] superview];
UITableView *table = (UITableView *)[cell superview];
NSIndexPath *textFieldIndexPath = [table indexPathForCell:cell];
NSUInteger row = [textFieldIndexPath row];
row++;
if (row > kNumOfEditableRows)
row = 0;
NSUInteger newIndex[] = {0, row};
NSIndexPath *newPath = [[NSIndexPath alloc] initWithIndexes:newIndex length:2];
UITableViewCell *nextCell = [self.tableView cellForRowAtIndexPath:newPath];
UITextField *nextField = nil;
for (UIView *oneView in nextCell.contentView.subviews)
{
if ([oneView isMemberOfClass:[UITextField class]])
nextField = (UITextField *)oneView;
}
[nextField becomeFirstResponder];
}
It was my idea to just create a second method (secondSectionTextFieldDone:) like this
-(IBAction)bottomTextFieldDone:(id)sender
{
UITableViewCell *cell = (UITableViewCell *)[[sender superview] superview];
UITableView *table = (UITableView *)[cell superview];
NSIndexPath *textFieldIndexPath = [table indexPathForCell:cell];
NSUInteger row = [textFieldIndexPath row];
row++;
if (row > 3)
row = 0;
NSUInteger newIndex[] = {0, row};
NSIndexPath *newPath = [[NSIndexPath alloc] initWithIndexes:newIndex length:2];
UITableViewCell *nextCell = [self.tableView cellForRowAtIndexPath:newPath];
UITextField *nextField = nil;
NSString *string = [NSString stringWithFormat:#"AutoEditCellID"];
for (UIView *oneView in nextCell.contentView.subviews)
{
NSLog(#"%#", nextCell.reuseIdentifier); /* DEBUG LOG */
if ([oneView isMemberOfClass:[UITextField class]] && (nextCell.reuseIdentifier == string))
nextField = (UITextField *)oneView;
}
[nextField becomeFirstResponder];
}
but the result does not solve the issue.
so my question is, how can i get the cursor to jump to the next textfield in the section that it is in, If there is one, and if not, then send a message "resignFirstResponder" so that, the keyboard goes away.
implement UITextFieldDelegate
yourFirstTextFeld.delegate = self;
yourSecondTextFeld.delegate=self;
implement this method
- (BOOL)textFieldShouldReturn:(UITextField *)theTextField {
if(theTextField==yourFirstTextFeld){
[yourSecondTextFeld becomeFirstResponder];
}
return YES;
}