简体   繁体   中英

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?

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]

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM