Re: UITableViewCell with UITextField

Gerriet M. Denkmann

On 26 Sep 2018, at 14:30, Alex Zavatone via Groups.Io <zav@...> wrote:

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.

@interface TextTableCell : UITableViewCell
@property IBOutlet UITextField *textField;


File’s Owner = TextTableCell
Outlet textField = UITextField

View UIView contains
Content View


- (void)viewDidLoad
[super viewDidLoad];
UINib *nib = [ UINib nibWithNibName: @"TableCellView" bundle: nil ];
[ self.tableView registerNib: nib forCellReuseIdentifier: kTextCell ];

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath;
NSLog(@"%s will dequeueReusableCellWithIdentifier: \"%@\"",__FUNCTION__, cellId);
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier: cellId forIndexPath: indexPath];


[tableView:cellForRowAtIndexPath:] will dequeueReusableCellWithIdentifier: "Cell with TextField"
*** Terminating app due to uncaught exception ‘NSUnknownKeyException', reason: '[<NSObject 0x6000032aeb80> setValue:forUndefinedKey:]: this class is not key value coding-compliant for the key textField.'

0 CoreFoundation 0x000000010251129b __exceptionPreprocess + 331
1 libobjc.A.dylib 0x0000000101a51735 objc_exception_throw + 48
2 CoreFoundation 0x0000000102510e09 -[NSException raise] + 9
3 Foundation 0x000000010147e0b4 -[NSObject(NSKeyValueCoding) setValue:forKey:] + 292
4 UIKitCore 0x0000000105176ada -[UIRuntimeOutletConnection connect] + 109
5 CoreFoundation 0x00000001024fcddd -[NSArray makeObjectsPerformSelector:] + 317
6 UIKitCore 0x00000001050906d1 -[UINib instantiateWithOwner:options:] + 1814
7 UIKitCore 0x00000001052ded16 -[UITableView _dequeueReusableViewOfType:withIdentifier:] + 611

I guess my TableCellView.xib is not quite right (or rather: absolutely messed up).
How to fix this?


Join { to automatically receive all group messages.