initwithstyle:reuseIdentifier: not called
If your cell is being created from a storyboard prototype (which you have declared as the custom class in IB) then it won't be created with initWithStyle...
but initWithCoder:
instead, like any other object loaded from a nib. If you have any setup code, it should be in there or in awakeFromNib
.
Custom UITableVIewCell initialization not called
If the cells come from a storyboard or nib file, then initWithStyle:reuseIdentifier
is not called, initWithCoder:
is called instead.
Here's a typical implementation of an overwritten initWithCoder:
:
-(id)initWithCoder:(NSCoder *)aDecoder
{
self = [super initWithCoder:aDecoder];
if (self) {
// Do your custom initialization here
}
return self;
}
Will not work if you need to access IBOutlet during custom initialization.
Overriding custom cell initWithStyle method but it's not being called
This initializer is called only when you call it explicitly. If you are loading your cells from a nib/storyboard, it won't be called.
Typically, we override awakeFromNib
method to customize cells loaded from nibs.
- (void)awakeFromNib {
[super awakeFromNib];
self.buttons = [[NSMutableArray alloc] initWithObjects:self.button1, self.button2, self.button3, self.button4, nil];
self.labels = [[NSMutableArray alloc] initWithObjects:self.label1, self.label2, self.label3, self.label4, nil];
}
Another note - instead of creating your buttons
array from button1
, button2
etc. you can use an IBOutletCollection
, e.g.
@property (nonatomic) IBOutletCollection NSArray *buttons;
and connect the buttons directly from Interface Builder but note that it doesn't keep the objects in any specific order.
initWithStyle:(UITableViewCellStyle) not called
The solution was simple
-(id)initWithCoder:(NSCoder *)aDecoder
{
NSLog(@"initWithCoder");
self = [super initWithCoder: aDecoder];
if (self)
{
}
return self;
}
custom initWithStyle: method
You don't normally create your own styles and if you dequeue a reusable cell this way, it doesn't call initWithStyle:
.
You should probably add your own "style" property to MyTableViewCell
with a different name and then set that property once you dequeue the cell.
Another way is to have different cell classes if the design of the cell is different. They can have a common base class if they share a lot of code.
no @interface for 'UITableView' declares the selector 'initWithStyle:reuseIdentifiers
UITableView *cell = [tableView dequeueReusableCellWithIdentifier:identifier];
should be
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:identifier];
you should allocate a UITableViewCell
not UITableView
like what you've done here.
//should be **UITableViewCell**
cell = [[[UITableView alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:identifier] autorelease];
and dont forget to return it later.
return cell;
awkakeFromNib,initWithCoder,initWithFrame not being called
The designated initializer for a UITableViewCell is initWithStyle:reuseIdentifier:, as is stated in the class reference. If you are not using a xib or storyboard to create your cell, that's the initializer that should be called.
Related Topics
Load a .Tmx (Tiled Map) in Sprite Kit
Flutter: Disable Swipe to Navigate Back in iOS and Android
How to Use Multiple Segues with One Uitableviewdelegate
iOS 7 When Rotating View in Tab Bar, Right Side of View Is Not Clickable
Cncopycurrentnetworkinfo with iOS 13
Warning in Custom Map Annotations Iphone
Xcode 7 Crash: [Nslocalizablestring Length] 30000
Always Got Nil Value from the Function in iOS
How to Convert Cmsamplebuffer to Data in Swift
Cgcolorgetcomponents() Not Returning the Correct Values for Black and for White
How to Find the Kind of Errors a Method May Throw and Catch Them in Swift
How to Draw on an Image in Swift
Rotate Sprite by Touch with a Limited Rotation Speed
Will Push Notification Still Work After Ownership Transfer in Itunesconnect
Nsinteralinconsistencyexception - Uikeyboardlayoutalignmentview
Prepare(For Segue: Uistoryboardsegue, Sender: Anyobject) Missing in Swift 3.0/Xcode 8 B6