【问题标题】:grouped style not working for UITableView分组样式不适用于 UITableView
【发布时间】:2014-08-12 06:12:11
【问题描述】:

我有一个拆分视图应用程序,它是通过将拆分视图控制器添加到情节提要中创建的。我有一个应该分组的表格视图,带有圆角和灰色背景,但它显示的是简单的样式。我像这样在应用程序委托中初始化视图:

self.dateController = [[DateViewController alloc] initWithStyle: UITableViewStyleGrouped];

其中 DateViewController 是我的自定义 TableViewController 类。这是 DateViewController.m 中的相关代码:

- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
    self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
    if (self) {
        [self.view setFrame: CGRectMake( 0, 260, 768, 764 )];
        toolbar = [[UIToolbar alloc] initWithFrame: CGRectMake( 0, 0, 768, 44 )];
        [self.view addSubview: toolbar];
    }
    return self;
}

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
    // Return the number of sections.
    return 2;
}

- (NSInteger) tableView: (UITableView *) tableView numberOfRowsInSection: (NSInteger) section {
    return 3;
}

什么可能导致我的表格视图没有被分组?谢谢!

【问题讨论】:

    标签: uitableview grouped-table


    【解决方案1】:

    终于找到答案了!我覆盖了错误的初始化函数。我使用了这段代码:

    - (id)initWithStyle:(UITableViewStyle)style
    {
        self = [super initWithStyle:UITableViewStyleGrouped];
        if (self) {
        }
        return self;
    }
    

    现在它可以工作了!

    【讨论】:

      猜你喜欢
      • 2016-12-12
      • 2021-01-23
      • 2020-10-19
      • 2021-04-25
      • 2016-07-11
      • 2020-04-28
      • 2011-06-08
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多