Re: UITableViewCell with UITextField

Alex Zavatone

Use an XIB for the subclass of tableViewCell, create a UIOutlet property for the UITextField, assign the subclass to the XIB’s class and wire up the UIOutlet property to the UITextField. Don’t forget to give the UITableViewCell an Identifier keyword.

Make sure to set the tableView to register the subclass for the cell if needed. I can dig up my working source, but it will be about 8 hours.

On Sep 26, 2018, at 2:25 AM, Gerriet M. Denkmann <g@...> wrote:

iOS 12, Xcode 10

I have a subclass of UITableViewController.

The UITableView should use UITableViewCells with UITextFields (for data entry).

So I created MyTableViewCellWithTextField which has:
@property IBOutlet UITextField *textField;
Changed the class of the Prototype Cell to MyTableViewCellWithTextField
added a UITextField to the ContentView and tried to connect the outlet to this textField.

But no luck.

So I have to do:

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath;
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier: cellId forIndexPath: indexPath];

UITextField *badHack = cell.contentView.subviews.firstObject;
badHack.keyboardType = …
badHack. placeholder = …
badHack. text = …

But I have a nagging feeling that this is *not* quite the right way.

What should I do instead ?


Join { to automatically receive all group messages.