Nitin
Nitin

Reputation: 151

how to make text field in tableview in iphone?

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....

Upvotes: 0

Views: 6612

Answers (4)

GameLoading
GameLoading

Reputation: 6708

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;        
}

Upvotes: 2

Nithin
Nithin

Reputation: 6475

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";

Upvotes: 4

PgmFreek
PgmFreek

Reputation: 6402

Tryout this code in CellForRowAtIndexPath:

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

Upvotes: 2

Jhaliya - Praveen Sharma
Jhaliya - Praveen Sharma

Reputation: 31722

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

Upvotes: 0

Related Questions