故事板中的原型单元不能创建UILabels等 [英] Prototype cell from storyboard not creating UILabels, etc

查看:95
本文介绍了故事板中的原型单元不能创建UILabels等的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的问题非常类似于这一个

我在Interface Builder中使用故事板设计的自定义原型单元将所有内部对象设置为nil(未创建),因此当我尝试为它们赋值时,它们保持空白。

My question is very similar to this one.
My custom prototype cells designed in Interface Builder using storyboards have all the internal objects set to nil (not created), so when I try to assign values to them, they remain blank.

我正在使用Xcode 4.6.2,并在6.1 iPhone模拟器中运行代码。这就是我所做的:

I am using Xcode 4.6.2, and running the code in the 6.1 iPhone simulator. Here is what I've done:


  • 在界面构建器中设计了一个带有必要字段的原型单元格。

  • 在代码中为此自定义单元格创建了UITableViewCell的子类,然后将界面生成器中的单元格设置为此类型。

  • 控制 - 将字段拖动到.h文件中,该文件为我设置对象(UILabels等)。我将单元格的标识符设置为serverNameCell

  • 设置数据源&将表委托给表所在的Viewcontroller。

  • 将表与ViewControler中的表对象相关联

  • designed a prototype cell in interface builder with the necessary fields.
  • created a subclass of UITableViewCell for this custom cell in code, and then set the cell in interface builder to this type.
  • control-dragged the fields into the .h file, which set up the objects (UILabels, etc) for me. I set the identifier of the cell to "serverNameCell"
  • set the datasource & delegate of the table to the Viewcontroller that the table is in.
  • associated the table with a table object in the ViewControler

此时,表格会显示正确的部分数量和数量。行,但没有设置单元格的值。

At the moment, the table displays with the correct number of sections & rows, but the values of the cell are not being set.

这是 cellForRowAtIndexPath:(NSIndexPath *)indexPath 代码:

NewServerCell *cell = [tableView dequeueReusableCellWithIdentifier:@"serverNameCell"];

我总是回到一个单元格,内存位置似乎可以用于有效对象。

I always get back a cell, and the memory location seems to be ok for a valid object.

但是当我尝试 cell.name.text = [thisServer name]; 我发现 cell.name 标签总是为零。

没有崩溃 - 但是我的字段没有设置。

But when I try to cell.name.text = [thisServer name]; I find that the cell.name label is always nil.
There are no crashes - but my fields are not being set.

我已经检查了一百万次标识符是好的 - 它是!
我已经浏览了故事板中自定义单元格的Apple文档 - 但仍然遇到这个令人沮丧的问题..

I have checked a million times that the identifier is ok - it is! I have gone through the Apple documentation for custom cells from a storyboard - but still get this frustrating issue..

其他人有这个,并解决了吗?

Anyone else had this, and resolved it?

推荐答案

今天我在Xcode 5的故事板上遇到了这个问题。把几乎所有剩余的头发拉出后,我注意到我在中调用了这个... viewDidLoad

I had this exact problem today with Xcode 5's storyboard. After pulling almost all my remaining hair out, I noticed I was calling this in viewDidLoad:

[self.tableView registerClass:[SwitchTableViewCell class] forCellReuseIdentifier:@Setting];

哎呀!在故事板中使用原型单元时,此行是不必要的。故事板会自动为我配置。 SwitchTableViewCell * tableViewCell = [tableView dequeueReusableCellWithIdentifier:@SettingforIndexPath:indexPath]; 工作正常而不调用 registerClass :: 明确。

Whoops! This line is unnecessary when using prototype cells in storyboards. The storyboard automatically configures this for me. SwitchTableViewCell *tableViewCell = [tableView dequeueReusableCellWithIdentifier:@"Setting" forIndexPath:indexPath]; works just fine without calling registerClass:: explicitly.

问题仍然是为什么调用 registerClass :: 会导致一些问题出口没有连接。

The question still remains of why calling registerClass:: causes some outlets to not be connected.

这篇关于故事板中的原型单元不能创建UILabels等的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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