0

I want to know how to make text field in tableview in iphone.

it means how to add uitextfield on uiTableviewCell and How handle it?

In order to handle means respond to it delegate and fetching value at the time of submission....

GameLoading
  • 6,552
  • 2
  • 31
  • 57
Nitin
  • 151
  • 6
  • 15

4 Answers4

4
UITextField *textField = [[UITextField alloc] initWithFrame:CGRectMake(0,0,320,50)];
textField.tag = 1000;
[cell.contentView addSubview:textField];
[textField release];

In customization part,

UITextField *textField = [[cell contentView] viewWithTag:1000];
textField.text = @"Your text";
Nithin
  • 6,307
  • 5
  • 40
  • 53
  • is possible to add multiple textfield here http://stackoverflow.com/questions/19621732/how-to-add-textfield-in-tableview-cell-and-access-each-textfields-text-by-their – Siva Oct 28 '13 at 07:15
2

Find the below link

Having a UITextField in a UITableViewCell or try this one

- (UITableViewCell *)tableView:(UITableView *)table cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    UITableViewCell *cell = [table dequeueReusableCellWithIdentifier:@"Cell"];
    if( cell == nil)
        cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"Cell"] autorelease];   

    cell.textLabel.text = [[NSArray arrayWithObjects:@"First",@"Second",@"Third",@"Forth",@"Fifth",@"Sixth",@"Seventh",@"Eighth",@"Nineth",@"Tenth",nil] 
                           objectAtIndex:indexPath.row];

    if (indexPath.row % 2) {
        UITextField *textField = [[UITextField alloc] initWithFrame:CGRectMake(0, 0, 200, 21)];
        textField.placeholder = @"Enter Text";
        textField.text = [inputTexts objectAtIndex:indexPath.row/2];
        textField.tag = indexPath.row/2;
        textField.delegate = self;
        cell.accessoryView = textField;
        [textField release];
    } else
        cell.accessoryView = nil;

    cell.selectionStyle = UITableViewCellSelectionStyleNone;
    return cell;        
}
Community
  • 1
  • 1
GameLoading
  • 6,552
  • 2
  • 31
  • 57
2

Tryout this code in CellForRowAtIndexPath:

UITextField *textField = [UITextField alloc] initWithFrame:CGRectMake(0,0,50,50)];
cell.contentView =textField;
[textField release];
PgmFreek
  • 6,234
  • 3
  • 32
  • 46
0

Create a instance of either UITextView Or UTextField and add it into the UITableViewCell as sub view.

Jhaliya - Praveen Sharma
  • 31,294
  • 8
  • 69
  • 74