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];
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);
Here is the code I am struggling with, the first table cell doesnt display the accessary arrow, but other table cells work fine...
Below is the code for table cell1, other cells is also customized but work fine.
- (void) initialization
{
labelTitle = [[UILabel alloc] initWithFrame:CGRectZero];
labelTitle.font = [UIFont fontForMoreLikeResultTitle];
labelTitle.textColor = [UIColor blackColor];
labelTitle.numberOfLines = 1;
labelTitle.lineBreakMode = UILineBreakModeTailTruncation;
labelTitle.backgroundColor = [UIColor clearColor];
labelFulLAddress = [[UILabel alloc] initWithFrame:CGRectZero];
labelFulLAddress.font = [UIFont fontForMoreLikeResultDescription];
labelFulLAddress.textColor = [UIColor blackColor];
labelFulLAddress.numberOfLines = 1;
labelFulLAddress.lineBreakMode = UILineBreakModeTailTruncation;
labelFulLAddress.backgroundColor = [UIColor clearColor];
[[self contentView] addSubview:labelTitle];
[[self contentView] addSubview:labelFulLAddress];
}
- (id)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
if (self)
{
// Initialization code
[self initialization];
}
return self;
}
- (void) layoutSubviews
{
float xOffset = 20.0f;
float yOffset = 10.0f;
float currentUsedHeight = yOffset;
labelTitle.text = documentTitle;
labelTitle.frame = CGRectMake(xOffset, currentUsedHeight,
320.0f - 2 * xOffset, 60.0f);
[labelTitle sizeToFitHeight];
[labelTitle sizeToFitWidth];
labelFulLAddress.text = #"99999 Bellevue Way NE, Bellevue WA";
currentUsedHeight += (yOffset + labelTitle.frame.size.height);
labelFulLAddress.frame = CGRectMake(xOffset, currentUsedHeight, 320.0f - 2 * xOffset, 60.0f);
[labelFulLAddress sizeToFitHeight];
[labelFulLAddress sizeToFitWidth];
}
Below is the code in view controller:
- (UITableViewCell *) createResultTableCell1:(UITableView *)tableView
{
static NSString *CellIdentifier = #"FirstMoreLikeResultCell";
FirstResultTableCell *cell = (FristResultTableCell *)[tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil)
{
cell = [[MoreLikeTableCell1 alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier];
cell.selectionStyle = UITableViewCellSelectionStyleNone;
cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
}
cell.documentTitle = self.documentTitle;
return cell;
}
- (UITableViewCell *) tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
UITableViewCell *cell;
if (indexPath.row == 0)
{
cell = [self createResultTableCell1:tableView];
}
else
{
cell = [self createResultTableCell2:tableView cellForRowAtIndexPath:indexPath];
}
return cell;
}
Call [super layoutSubviews] from within your overridden layoutSubviews.
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.
I am getting memory leak at text fiels please suggest me how to resolve it.
I written the code in init() as:
eventTextField = nil;
eventTextField = [[UITextField alloc]initWithFrame:CGRectMake(10, 15, 300, 50)];
eventTextField.placeholder = #"Event Name";
[eventTextField setFont:[UIFont boldSystemFontOfSize:14]];
eventTextField.returnKeyType = UIReturnKeyDone;
eventTextField.keyboardAppearance = UIKeyboardAppearanceDefault;//Showing leak at this line
eventTextField.keyboardType = UIKeyboardTypeDefault;
eventTextField.delegate=self;
and I released it in dealloc method.
and in cellForRowIndex I am adding it as subview.
- (UITableViewCell *)tableView:(UITableView *)tv cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:#"MasterViewIdentifier"];
if (cell == nil)
{
cell = [[[UITableViewCell alloc] initWithFrame:CGRectZero reuseIdentifier:#"MasterViewIdentifier"] autorelease];
cell.selectionStyle = UITableViewCellSelectionStyleNone;
UIView* elementView = [[UIView alloc] initWithFrame:CGRectMake(20,170,320,280)];
elementView.tag = 0;
elementView.backgroundColor=[UIColor clearColor];
[cell.contentView addSubview:elementView];
[elementView release];
}
UIView* elementView = [cell.contentView viewWithTag:0];
elementView.backgroundColor=[UIColor clearColor];
for(UIView* subView in elementView.subviews)
{
[subView removeFromSuperview];
}
if(indexPath.section == 0 && indexPath.row == 0)
{
CorkItAppDelegate* appDelegate = (CorkItAppDelegate*)[[UIApplication sharedApplication] delegate];
cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
wineNameTitleLabel.numberOfLines = 0;
[wineNameTitleLabel setFont:[UIFont boldSystemFontOfSize:14]];
if(appDelegate.isNewWine == YES)
{
wineNameTitleLabel.textColor = [UIColor blackColor] ;
wineNameTitleLabel.text = appDelegate.getNewWineName;
}
else
{
if([event.eventWineName length]>0)
{
wineNameTitleLabel.textColor = [UIColor blackColor] ;
wineNameTitleLabel.text = event.eventWineName;
}
else
{
wineNameTitleLabel.text = #"Wine Name";
}
}
[elementView addSubview:wineNameTitleLabel];
}
else if(indexPath.section == 1)
{
if(isRightButton == YES)
{
eventTextField.enabled = NO;
}
else
{
eventTextField.enabled = YES;
}
if([event.eventName length] > 0)
{
eventTextField.text = event.eventName;
}
else
{
eventTextField.text = #"";
}
[elementView addSubview:eventTextField];
cell.accessoryType = UITableViewCellAccessoryNone;
}
return cell;
}
Hope I get wucik response from your side.
Thanks in advance,
Monish.
If you still need the eventTextField. You should create a property and instance variable for it. So that, you can your class own the eventTextField and release it in the dealloc. Like this:
#interface A {
UITextField *eventTextField;
}
#property (nonatomic, retain) UITextField *eventTextField;
#end
#implementation A
#synthesize eventTextField;
- (id)init {
eventTextField = [[UITextField alloc]init];
}
- (void)dealloc {
[eventTextField release];
}
#end
you should release the UITextField after adding it to the subview
[foo addSubview:eventTextField];
[eventTextField release];
eventTextField = nil; is unnecessary btw as eventTextField is a ivar is already zeroed (pointer set to 0x0(nil))
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;
}