In a UITableView, I would like to be able to edit the cell.textLabel.text property of the row, when such row is touched.
In other terms, I would like to be able to edit the row directly touching it, instead of entering into edit mode.
How can I implement this?
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *CellIdentifier = @"Cell";
CMTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {
cell = [[[CMTableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier] autorelease];
}
int tagsCount = [[currentComic Tags] count];
[[cell textField] setTag:[indexPath row]];
[[cell textField] setText:[tagsDisplayName objectAtIndex:[indexPath row]]];
return cell;
}
And this is the subclass CMTableViewCell:
...
-(void)viewDidLoad
{
textField = [[UITextField alloc] init];
[textField setFrame:CGRectMake(5,5,50,400)];
[self addSubview:textField];
}
Add
UITextFieldwithout borders as subview. Before adding it to subview – set Tag nubmer toUITextFieldfromindexPath.rowattableview cellForRowAtIndexPathmethod. When user entered data – save it withUITextFieldDelegatemethods when “Return” button was pressed. Unfortunately I can’t give you code, because right now I’m on Windows. Home this will helpUPDATE: Tag number needed to change data in your DataSource. When you pressed “Return” button in your UITextField, you can save changed by getting UITableViewCell by this tag number from UITextField.