I have created some tables with text fields inside, like in the contacts for the iphone,
(inspired from UICatalog example)
all is working, but how can I programatically read the values of this text fields, I see they have a tag, but how can I read from them (because I cannot use the IB for this as they were created programatically to go inside the tables)(noob here!)
thanks,
Im using some example hello world style where I type on the text field of the table, then click on button and the text typed goes to label,
This sample is to ultimately populate my coredata db from the table textfields
As I said im preatty noob for this so please walk me trough
so when user hit submit, I get the text to the label (and soon to coredata)
- (IBAction) submitYourName;{
lblUserTypedName.text = txtUserName.text;
NSLog(@"received");
}
this is the code for my textfield
- (UITextField *)textFieldNormal
{
if (textFieldNormal == nil)
{
CGRect frame = CGRectMake(kLeftMargin, 8.0, kTextFieldWidth, kTextFieldHeight);
textFieldNormal = [[UITextField alloc] initWithFrame:frame];
textFieldNormal.borderStyle = UITextBorderStyleRoundedRect;
textFieldNormal.textColor = [UIColor blackColor];
textFieldNormal.font = [UIFont systemFontOfSize:17.0];
textFieldNormal.placeholder = @"<enter text>";
textFieldNormal.backgroundColor = [UIColor whiteColor];
textFieldNormal.autocorrectionType = UITextAutocorrectionTypeNo; // no auto correction support
textFieldNormal.keyboardType = UIKeyboardTypeDefault; // use the default type input method (entire keyboard)
textFieldNormal.returnKeyType = UIReturnKeyDone;
textFieldNormal.clearButtonMode = UITextFieldViewModeWhileEditing; // has a clear 'x' button to the right
textFieldNormal.tag = kViewTag; // tag this control so we can remove it later for recycled cells
textFieldNormal.delegate = self; // let us be the delegate so we know when the keyboard's "Done" button is pressed
// Add an accessibility label that describes what the text field is for.
[textFieldNormal setAccessibilityLabel:NSLocalizedString(@"NormalTextField", @"")];
}
return textFieldNormal;
}
and this to show that text field in the table cell
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
UITableViewCell *cell = nil;
static NSString *kCellTextField_ID = @"CellTextField_ID";
cell = [tableView dequeueReusableCellWithIdentifier:kCellTextField_ID];
if (cell == nil)
{
// a new cell needs to be created
cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault
reuseIdentifier:kCellTextField_ID] autorelease];
cell.selectionStyle = UITableViewCellSelectionStyleNone;
}
else
{
// a cell is being recycled, remove the old edit field (if it contains one of our tagged edit fields)
UIView *viewToCheck = nil;
viewToCheck = [cell.contentView viewWithTag:kViewTag];
if (viewToCheck)
[viewToCheck removeFromSuperview];
}
UITextField *textField = [[self.dataSourceArray objectAtIndex: indexPath.section] valueForKey:kViewKey];
[cell.contentView addSubview:textField];
return cell;
}
@Mako take help from here
Here appDelegate is the object of your Application Delegate class
// Customize the appearance of table view cells.
Hope you understand…Good Luck!