gpt4 book ai didi

ios - iOS程序化分组表为空

转载 作者:行者123 更新时间:2023-12-01 19:13:49 25 4
gpt4 key购买 nike

我有一个以编程方式实现的分组形式的tableView。

我所得到的只是应该填充的灰色细条纹。所以它正在加载,但不是。。。。。。

还需要什么?
如果没有更多的东西,那我应该去哪里呢?

另外,如何使表格的背景颜色与单元格的白色相同?

- (void)loadView {

[super loadView];

UITableView *view = [[UITableView alloc] initWithFrame:[UIScreen mainScreen].applicationFrame style:UITableViewStyleGrouped];

[view setAutoresizingMask:UIViewAutoresizingFlexibleHeight|UIViewAutoresizingFlexibleWidth];

self.view = view;

[view reloadData];

}

viewDidLoad是否必要?
- (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view.
}

谢谢,
  • Morkrom
  • 最佳答案

    您必须为tableView提供数据。

    对于州长,您需要定义一个dataSource。仅将viewController用作数据源是很常见的。

    // in the .h find something similar and add <UITableViewDataSource>
    @interface ViewController : UIViewController <UITableViewDataSource>

    然后当您创建tableView时。
    view.datasource = self;

    然后,您需要提供数据本身。实现这些方法:
    #pragma mark - UITableView Datasource

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

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

    - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
    {
    static NSString *cellIdentifier = @"Cell";

    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:cellIdentifier];

    if (!cell) {
    cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellIdentifier];
    }

    [cell.textLabel setText:@"A Cell"];

    return cell;
    }

    这些方法将创建3个节,每个节有3行。所有的单元格只会说一个单元格。这是所有tableViews的基础。只需自定义数据即可:)

    关于ios - iOS程序化分组表为空,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14607926/

    25 4 0
    Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
    广告合作:1813099741@qq.com 6ren.com