Save my hair, please or point out my (obvious) error. I am trying to use a UITableViewStyle of UITableViewCellStyleSubtitle
in a subclassed UITableViewController.
I define a static constant in the implementation:
static NSString * const kAHCellIdentifier;
In viewDidLoad
I register a tableView class:
[self.tableView registerClass:[UITableViewCell class] forCellReuseIdentifier:kAHCellIdentifier];
Then in tableView:cellForRowAtIndexPath
I initialise the the cell as follows:
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:kAHCellIdentifier];
if (cell == nil) {
cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:kAHCellIdentifier];
}
When running the app (device or sim) the cells load but the detailTextLabel doesn't show, however if I initialise like this, it works correctly*
My guess is that the constant is not actually static, or that there is a bug (8.0.2), or there is something that I am missing completely due to lack of sleep or whatever.
It can also be noted, that if I don't register the class there is a compiler error (expected) but no error even though the cell identifiers are different (which I guess is expected as I could register different classes for different cell styles.
What am I missing?
Edit
Using [tableView dequeueReusableCellWithIdentifier:kAHCellIdentifier forIndexPath:indexPath];
has no effect either.
Shorter question
Why does the dequeueReusableCellWithIdentifier
return nil and thus initiate the cell using the UITableViewCellStyle in the cell == nil
block if I use a static NSString in the cellForRowAtIndexPath
method call, and not, if I use a class level global constant as defined above.
Additional
Some more testing has yielded some different results. If you register a class for the cell reuse identifier and then give the cell a different identifier in cellForRowAtIndexPath
then it works. If you give it the same name as the registered class, then it doesn't work as expected.
Answer
After some testing, and @MANIAK_dobrii's answer, some clarity.
If you want to use the newer cell dequeue method dequeueReusableCellWithIdentifier:forIndexPath
and need to use a UITableViewCellStyle
other than default, you'll need to subclass UITableViewCell
and override the tableview style in the initWithStyle
method call.
If you are happy to use the older method then make sure you don't register a class for the reuse identifier otherwise it will not work.