Re: UITableViewCell with UITextField


Alex Zavatone
 

Try adding nonatomic and strong to your property.

@property (nonatomic, strong) IBOutlet UITextField *textField;

Also, did you set the XIB in the storyboard to your subclass and drag the UITextField to your property?

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



On 26 Sep 2018, at 14:30, Alex Zavatone via Groups.Io <zav=mac.com@groups.io> 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;
@end


TableCellView.xib

File’s Owner = TextTableCell
Outlet textField = UITextField

View UIView contains
TextTableCell
Content View
UITextField


MyTableViewController

- (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];
}


Result:

[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?

Gerriet.



Join cocoa@apple-dev.groups.io to automatically receive all group messages.