Editing TextLabel in a UITableViewCell

Possible duplicate:
How to do in-place editing in a UITableView?

I am new to this iphone development. I just want to know how to edit / update a UITextLabel in a tableView.

I already use edit / done animation and can delete lines, but I can’t get how to edit the text in these lines.

I want the user to edit the text label of the cell. When the edit button is pressed.

I already searched the site, but could not get the exact answer.

-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"CellIdentifier"];
if(!cell)
{
    cell = [[[UITableViewCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"CellIdentifier"]autorelease];
    cell.editingAccessoryType=YES;
}


myTextField = [[UITextField alloc] initWithFrame:CGRectMake(15, 6, 241, 31)];
myTextField.backgroundColor = [UIColor clearColor];
myTextField.textAlignment = UITextAlignmentLeft;
myTextField.returnKeyType = UIReturnKeyDone;
myTextField.delegate = self;
cell.accessoryView = myTextField;
myTextField.text = [self.arrayOfItems objectAtIndex:indexPath.row];
myTextField.enabled = NO;
return cell;
}

-(IBAction)Edit:(id)sender
{
if(self.editing)
{
            [myTextField.Enabled = YES];
    [super setEditing:NO animated:NO];
    [self.tab setEditing:NO animated:NO];
    [self.tab reloadData];
    [self.navigationItem.rightBarButtonItem setTitle:@"Done"];
    [self.navigationItem.rightBarButtonItem setStyle:UIBarButtonItemStylePlain];
}
else 
{
    myTextField.enabled= YES;

    [super setEditing:YES animated:YES];
    [self.tab setEditing:YES animated:YES];
    [self.tab reloadData];
    [self.navigationItem.rightBarButtonItem setTitle:@"Edit"];
    [self.navigationItem.rightBarButtonItem setStyle:UIBarButtonItemStyleDone];
 }
 }

- (UITableViewCellEditingStyle)tableView:(UITableView *)aTableView editingStyleForRowAtIndexPath:(NSIndexPath *)indexPath 
{
if (self.editing == NO || !indexPath) 
return UITableViewCellEditingStyleNone;
if (self.editing && indexPath.row == ([self.arrayOfItems count])) 
{
    return UITableViewCellEditingStyleInsert;
} 
else 
{
    return UITableViewCellEditingStyleDelete;
}
return UITableViewCellEditingStyleNone;
}

This does not work for me.textfield disappears if I click the edit button

+5
source share
4 answers

, , .. ( ..). , , , mid-edit .. (. . ..).

UILabel , UITextField .

- , , / .

"", . , reloadData View viewWillAppear.

/ .

+1

UITextField UILabel , . . Tutorial Apple.

+1

UITableViewCell, :

//Get the first cell of the first section
NSIndexPath *ip = [NSIndexPath indexPathForRow:0 inSection:0];
UITableViewCell *cell = [tableView cellForRowAtIndexPath:ip];

//Change the textLabel contents
[[cell textLabel] setText@"Updated text"];

//Refresh the tableView
[tableView reloadData];
0
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
.........

cell.textLabel.text = @"my text";

return cell;
}
-2

All Articles