Editing text in place in a UITableViewCell?

I know this should be a very simple question, but it's hard for me to find it in a simple place where there are not many other things that can isolate a specific behavior.

I know that I need to add a UITextField as a subtask in a UITableViewCell to make it editable. What is the best way to do this? (I see an example in UICatalog, but I'm confused with all the extra things that it does with the Dictionary.)

Again, please excuse my ignorance of this issue. A pointer to a sample code or screencast would be highly appreciated.

Thanks in advance,

Alan

+10
source share
2 answers

First define about UITextField.

txtField=[[UITextField alloc]initWithFrame:CGRectMake(5, 5, 320, 39)];
txtField.autoresizingMask=UIViewAutoresizingFlexibleHeight;
txtField.autoresizesSubviews=YES;
txtField.layer.cornerRadius=10.0;
[txtField setBorderStyle:UITextBorderStyleRoundedRect];
[txtField setPlaceholder:@"Type Data Here"];

cellForRowAtIndexPath method

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
     static NSString *CellIdentifier = @"CellIdentifier";
     UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
   if (cell == nil)
   {
      cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier] autorelease];
      cell.accessoryType = UITableViewCellAccessoryNone;
    }
    [cell addSubview:txtField];
    return cell;
}
+4

UITableViewCell , . UITableView. , UITextField , IMHO UIViewController, UITableView, DataSource, .

+1

All Articles