0

I have to tableview designs for ios7/6 - in ios6 I need to implement a tableview grouped style and in ios7 I need a plain one. So In storyboards I change the style to plain and in viewDidLoad of the subclass of UITableViewController I have something like this:

if (!IS_OS_7_OR_LATER) {
    self = [[UITableViewController alloc] initWithStyle:UITableViewStyleGrouped];
}

But it doesn't work. I tried to use initWithCoder method but can't get the good result. Any help?

ShurupuS
  • 2,923
  • 2
  • 24
  • 44
  • you cant change self inside of a method and expect that to actually change who you are... you can maybe change the style... but when you say self = ... you are just setting a local variable at that point – Grady Player Nov 12 '13 at 22:33

3 Answers3

1
- (id)initWithFrame:(CGRect)frame style:(UITableViewStyle)
{
    bool isLowerOrEqualToSix = (floor(NSFoundationVersionNumber) <= NSFoundationVersionNumber_iOS_6_1);

    if (isLowerOrEqualToSix) { // iOS 6 or lower
        [super initWithFrame:frame style:UITableViewStyleGrouped];
    } else { // iOS 7 or higher
        [super initWithFrame:frame style:UITableViewStylePlain];
    }
}

This is what you need.

0

Try subclassing UITableView, and override this method:

-(id)initWithFrame:(CGRect)frame style:(UITableViewStyle)
{
    if (!IS_OS_7_OR_LATER) {
          [super initWithFrame:frame style:UITableViewStyleGrouped];
     } else
          [super initWithFrame:frame style:UITableViewStylePlain];
}

Then, on Interface Builder, set the class of your tableView to be the derived class you just created.

neutrino
  • 2,297
  • 4
  • 20
  • 28
0

As stated in tableview class reference the style property has to be set at initialization. It cannot be changed after this. In code you would do this with if statement checking ios version and initializing with appropriate style. Using storyboards follow this link How to switch to different Storyboard for iPhone 5?

Community
  • 1
  • 1
Titch
  • 3
  • 2