简体   繁体   English

如何以编程方式将TableView设置为分组

[英]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 我正在尝试从配置文件动态设置我的TableView,并且一直在尝试覆盖以下模板代码

- (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). 2条注释行有效(模板随附2条注释行)。 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 UITableViewStyle不是指针类型

@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]

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何设置UITableView的背景(tableview样式为“Grouped”)才能使用图像? - How can I set the background of UITableView (the tableview style is “Grouped”) to use an image? iPhone:如何保持分组表格视图的边框但将其背景设置为透明 - iPhone: how can I keep the borders of grouped tableview but set its background to transparent 如何访问分组表格视图的一个特定部分? - How can I access one particular section of a grouped tableview? 如何在分组的Tableview单元中使图像的宽度等于屏幕的宽度? - How can I make an image in a grouped tableview cell the width of the screen? [iPhone]如何设置分组tableview部分的填充? - [iPhone]How to set padding of grouped tableview section? 我可以将按钮添加到分组的tableView的各个部分吗? - Can I add buttons to sections of grouped tableView? 如何设置以编程方式创建的TableView的子类? (没有情节提要) - How to set the subclass of a TableView that was created programmatically? (no storyboards) 如何为分组样式的UITableView设置节标题的外观? - How can I set the appearance of section headings for a grouped style UITableView? 如何使用分组样式设置UITableView边框 - How can I set the UITableView border with a grouped style 如何将tableView中的所有单元格设置为选中或未选中? - How can I set all cells in a tableView as checked or unchecked?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM