Possible Duplicate:
How to do edit-in-place in a UITableView?
I am new to this iphone developing. I just want to know how to edit/update UITextLabel in a tableView.
I am already using edit/done animation and able to delete rows but i am not able to get how to edit the text in those rows.
I want the user to edit the textlabel of the cell.when edit button is tapped.
i already searched the site but couldnt 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 is not working for me.textfield is disappearing if i hit edit button