Anthony Main
Anthony Main

Reputation: 6068

How can I programmatically set a TableView to be grouped

I am trying to set up my TableView dynamically froma configuration file and have been trying to override the following template code

- (id)initWithStyle:(UITableViewStyle)style {
    // Override initWithStyle: if you create the controller programmatically and want to perform customization that is not appropriate for viewDidLoad.
    JeanieAppDelegate *appDelegate = (JeanieAppDelegate *)[[UIApplication sharedApplication] delegate];

    if (self = [super initWithStyle:(UITableViewStyle*)appDelegate.skin.tableViewStyle]) {
    //1 if (self = [super initWithStyle:UITableViewStyleGrouped]) {
    //2 if (self = [super initWithStyle:style]) {
    }
    return self;
}

The 2 commented lines work (no 2 is one which comes with the template). I have defined my variable using the default enum as follows:

@interface Skin : NSObject {
    UITableViewStyle *tableViewStyle;   
}

@property (nonatomic) UITableViewStyle *tableViewStyle; 

@end

However my code return an incompatible type error, any ideas why?

Upvotes: 0

Views: 1491

Answers (1)

Alex Wayne
Alex Wayne

Reputation: 186994

UITableViewStyle is not a pointer type

@interface Skin : NSObject {
    UITableViewStyle tableViewStyle;   
}

@property (nonatomic) UITableViewStyle tableViewStyle; 

@end

And you shouldn't need to cast it in the argument to the supermethod there. The compiler should know what type it is.

[super initWithStyle:appDelegate.skin.tableViewStyle]

Upvotes: 2

Related Questions