1

Possible Duplicate:
Having a UITextField in a UITableViewCell

I try to do it for a couple of days, but I found nothing useful so my question is: how can I create UITableViewCell UITextField Like?

http://i.stack.imgur.com/poeay.png

Community
  • 1
  • 1
Ziad Tamim
  • 330
  • 6
  • 17

4 Answers4

3

You can add it to cell contentView like this

UITextField *textField = [[UITextField alloc] initWithFrame:rect];
textField.tag = textTag;

//Add textfield to contentView
[cell.contentView addSubview:textField];

Remember to tag it, because when you reuse a cell the contentView is NOT cleared, so you should just use the same UITextView to get it later like this:

UITextField *textField = (UITextField *)[cell.contentView viewWithTag:textTag];

Additionally I have noticed the first time you create it, and add your textfield to the contentView and then modify the mainLabel, that subview will go on top so before returning the cell do this:

[cell.contentView bringSubviewToFront:textField];
Oscar Gomez
  • 18,102
  • 12
  • 80
  • 113
2

just add the UITextField to a UITableViewCell like this..

UITextField* textField = [[UITextField alloc] initWithFrame:frame]; 

[cell addSubview:textField];
Aravindhan
  • 15,380
  • 10
  • 51
  • 71
  • 1
    You shouldn't add subviews to the cell directly but to its contentView. Apple docs: "The content view of a UITableViewCell object is the default superview for content displayed by the cell. If you want to customize cells by simply adding additional views, you should add them to the content view so they will be positioned appropriately as the cell transitions into and out of editing mode." – jbat100 Oct 25 '11 at 15:21
  • How can i use them in my code when i want to recuperate the values for doing something? – Ziad Tamim Oct 25 '11 at 16:23
  • @ziadtamim: Make an instance variable or property for the pointer to the text field, and store that pointer there after you create the field. Optionally, make the property an outlet, and create the field in a nib (instead of in code) and hook up the outlet to it. – Peter Hosey Oct 25 '11 at 19:05
2

You can create this in the interface builder. Drag a UITableViewCell into the work area, put in your UILabel or UITextField. You can customize the look if you want.

Now in your view controller, declare an IBOutlet for this UITableViewCell. When the program calls cellForRowAtIndexPath, you can simply make cell equal to that variable.

Another approach is to add a UITextField in the cell's contentview programmatically.

Jonats
  • 381
  • 2
  • 7
1

You can create a UIView with some UILabels and some UITextField inside. And with the library and the property cornerRadious of the layer of the view you cand do the rounded borders

gfdgfd
  • 104
  • 1
  • 11