Accept text input from uitableviewcell

I am developing an application where I need to take text input from a user using a sectional view of a table. I never used a table view to input text input from a user. Please take a look at the image to understand the test.

enter image description here

I tried this in-place text editing in a UITableViewCell?

but it doesn’t fill what I wanted.

when I use the following code, I get output that is not like the previous image.

UITextField *txtField=[[UITextField alloc]initWithFrame:CGRectMake(45, 0, cell.frame.size.width, cell.frame.size.height)];
    txtField.autoresizingMask=UIViewAutoresizingFlexibleHeight;
    txtField.autoresizesSubviews=YES;
    [txtField setBorderStyle:UITextBorderStyleRoundedRect];
    [txtField setPlaceholder:@"Type Data Here"];

    if (cell == nil)
    {
        cell.accessoryType = UITableViewCellAccessoryNone;
    }
    [cell addSubview:txtField];

enter image description here

see answer to questions 3 and 5.

Thank.

+3
source share
3 answers

UITextField , "". , , indexpath.section indexpath.row cellForRowAtIndexPath:

:

if(indexPath.section == CELL_SECTION) {
    if(indexpath.row == CELL_ROW_INDEX) {
      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"];
      [cell.contentView addSubView:textField];
   }
}
+4

  • subclass UITableViewCell.

  • , TextField (TF) TF

  • TF .

  • tableView:celForRowAtIndexPath: TF tf = [cell viewWithTag: YOUR_TAG];

  • , .

  • , , ,

    .

    . tableView cellforRowAtIndexPath 4 5

+1

You need custom UITableViewCells UITextfield. You can probably set tagfor textFieldfor each cell to identify them. You can also implement UITextFieldDelegateif you want to get some kind of text check or something else. Then you can get the value for textFieldbased on the tag.

0
source

All Articles