When UITableViewCell is loaded first time from Storyboard via dequeueReusableCellWithIdentifier: viewWithTag: returns nil object. But on second and next reloads it returns proper object.
My tableView is embedded in UIViewController(in Storyboard) with prototype cells
cellAttachment = [_tableView dequeueReusableCellWithIdentifier:@"cellAttachment"];
UIButton *btnAttachment = nil;
btnAttachment = (UIButton*)[cellAttachment viewWithTag:10];
When cellAttachment is loaded first time, btnAttachment is nil. On next reload btnAttachment is returned properly.
Cell View hierarchy first load
(lldb) po [cellAttachment recursiveDescription]
<UITableViewCell: 0x7fd3e611cc20; frame = (0 0; 0 0); layer = <CALayer: 0x7fd3e611be00>>
| <UITableViewCellContentView: 0x7fd3e3fc9850; frame = (0 0; 0 0); clipsToBounds = YES; opaque = NO; gestureRecognizers = <NSArray: 0x7fd3e611b6a0>; layer = <CALayer: 0x7fd3e611bd00>>
| <_UITableViewCellSeparatorView: 0x7fd3e611cf20; frame = (0 -1; 15 1); layer = <CALayer: 0x7fd3e611c020>>
Cell view hierarchy on next reloads
(lldb) po [cellAttachment recursiveDescription]
<UITableViewCell: 0x7fd3e611cc20; frame = (0 179; 320 42); hidden = YES; autoresize = W; layer = <CALayer: 0x7fd3e611be00>>
| <UITableViewCellContentView: 0x7fd3e3fc9850; frame = (0 0; 320 42); opaque = NO; gestureRecognizers = <NSArray: 0x7fd3e611b6a0>; layer = <CALayer: 0x7fd3e611bd00>>
| | <UIButton: 0x7fd3e611d0f0; frame = (286 6; 15 22); opaque = NO; autoresize = RM+BM; tag = 10; layer = <CALayer: 0x7fd3e611c0b0>>
| | | <UIImageView: 0x7fd3e6015410; frame = (0.5 1; 14 20); clipsToBounds = YES; opaque = NO; userInteractionEnabled = NO; layer = <CALayer: 0x7fd3e3ccd960>>
| <_UITableViewCellSeparatorView: 0x7fd3e611cf20; frame = (0 -1; 15 1); layer = <CALayer: 0x7fd3e611c020>>
| <UIView: 0x7fd3e3c4c140; frame = (15 41; 305 1); layer = <CALayer: 0x7fd3e3cecb40>>
After having the issue I compared my old working files with new storyboard files to know what may cause such a behavior. After doing that I was able to fix my problem in one of following ways.
1: Enable 'Installed' field on each subview of UITableViewCell
OR
2: Disable 'Use size classes' on .storyboard file
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With