4

I know i can register a class or NIB file as a UITableViewCell. But I want to do the iOS 6 way of

UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (!cell) {
    cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle
                                  reuseIdentifier:CellIdentifier];

How could I achieve this (specifying the cell style) while still using registerClass:ForReuseIdentifier:

ColemanCDA
  • 964
  • 7
  • 13
  • Why would you do this? Using `registerClass` makes no sense if you make use of registerClass, since they are orthogonal to eachother. – Hampus Nilsson Mar 27 '13 at 19:12
  • Possible duplicated of: http://stackoverflow.com/questions/13174972/setting-style-of-uitableviewcell-when-using-ios-6-uitableview-dequeuereusablecel – 3lvis Oct 06 '13 at 15:38

1 Answers1

2

If you use register class or register nib, then you don't use the if(! cell) clause at all, and you should use dequeueReusableCellWithIdentifier:forIndexPath: instead of the one you're using. You will get whatever style you created in your nib or class. Usually, that wouldn't be any of the Apple default styles, it would be your own custom style.

If you just want one of Apple's predefined styles, then the easiest way is to choose that style in IB and give it a reuse identifier -- in that circumstance, you should register anything, the system will automatically get the cell from the storyboard.

rdelmar
  • 103,982
  • 12
  • 207
  • 218