如何填充静态UITableView [英] how to populate a static UITableView

查看:93
本文介绍了如何填充静态UITableView的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我尝试了几种方法,但似乎我缺少了一些东西.

I tried several ways but it seems I'm missing something..

这是我使用的代码:

- (void)configureView
{
// Update the user interface for the detail item.
  if (self.detailItem) {
    for (int idx=0; idx<16; idx++) {
        NSIndexPath *indexPath = [[NSIndexPath alloc] initWithIndex:idx];
        [self.tableView cellForRowAtIndexPath:indexPath].detailTextLabel.text = [param objectAtIndex:idx];
    }
    self.detailDescriptionLabel.text = [self.detailItem description];
  }
}

我在viewDidLoad上称呼它.我的tableview有16个静态单元格,并且我使用的是标准的字幕"类型的单元格,因此在这方面不需要自定义. textLabel.text 在设计时填充.我的tableview也在tableViewController中.我还尝试了标准的Tableview填充,但似乎静态单元格与这种方式不符.

I call this on viewDidLoad. My tableview has 16 static cells, and I'm using standard "Subtitle" type cell, so no customization needed on that front. textLabel.text is filled at design time. Also my tableview is in a tableViewController. I also tried with standard population of tableview but it seems static cells don't agree with that way.

我在做什么错了?

@jrturton我做了一些更改以查看发生了什么:

@jrturton I did some changes to see what's going on:

我在 for 行下添加了这三行,以查看是否有任何内容:

I added these three lines under for line to see if there's anything there:

        UITableView *tv = self.tableView;
        UITableViewCell *cell = [tv cellForRowAtIndexPath:[NSIndexPath indexPathForRow:idx inSection:0]];
        NSString *label = [[NSString alloc] initWithString:cell.textLabel.text];

首先,电视分配正确,我可以看到.但是除了那个单元格和标签之外,它是空的.甚至电视都没有行信息..

First of all tv is assigned correctly, I can see that. But other than that cell and label comes empty. Even tv has no row information it seems..

可能是因为tableview已将数据源和委托分配给tableviewcontroller ..我想我听说它不应该是那样的或类似的东西...

Could it be because tableview has datasource and delegate assigned to the tableviewcontroller.. I think I heard it shouldn't be like that or something...

@jrturton这是:

@jrturton Here it is:

希望这会有所帮助.

推荐答案

某些日志记录会迅速向您显示索引路径无效,因此不会返回任何单元格.

Some logging would quicky show you that your index path is not valid and therefore no cell is being returned.

要创建要在UITableView中使用的NSIndexPath,请使用以下方法:

To create an NSIndexPath for use in a UITableView, use this method:

[NSIndexPath indexPathForRow:idx inSection:0];

索引路径必须包含一行和一部分才能供表理解.

The index path has to contain a row and section for the table to understand it.

您还需要从viewWillAppear:而不是viewDidLoad调用此函数,因为静态表并未尽早填充.然后,您必须首先致电[super viewWillAppear:animated]

You also need to call this from viewWillAppear: rather than viewDidLoad, the static table is not populated that early on. And you must call [super viewWillAppear:animated] first!

这篇关于如何填充静态UITableView的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆