How to make tableviewcell text editable on touch i

2019-07-26 21:11发布

问题:

In my iPhone app, I have a table view.

I want that when the user selects (or basically touches) on the cell of the tableview then he/she should be able to edit the cell contents.

How can I do that?

回答1:

@PARTH in order to make your UITableView cells editable i suggest u to give textfields to your cell....

eg:- In

-(UITableViewCell *)reuseTableViewCellWithIdentifier:(NSString *)identifier withIndexPath:(NSIndexPath *)indexPath {


    CGRect cellRectangle = CGRectMake (0, 10, 300, 70); 
    CGRect Field1Frame = CGRectMake (10, 10, 290, 70);
    UITableViewCell *cell = [[[UITableViewCell alloc] initWithFrame:cellRectangle reuseIdentifier:identifier] autorelease];
    UITextField *textField;


    //Initialize Label with tag 1.

    textField = [[UITextField alloc] initWithFrame:Field1Frame];

    textField.tag = 1;
    [cell.contentView addSubview:textField];

[textField release];
    return cell;
}

and in your cellForRowAtIndexPath method // Configure the cell.

 UITextField *txtTemp = (UITextField *)[cell.contentView viewWithTag:1];

use this where u want in your tableview accordingly otherwise hide it.....Hope it will help u!!



回答2:

you need to put text field inside the table cell use this link.