dequeueReusableCellWithIdentifier使用storyboard静态单元格返回nil [英] dequeueReusableCellWithIdentifier returns nil using storyboard static cells

查看:184
本文介绍了dequeueReusableCellWithIdentifier使用storyboard静态单元格返回nil的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我对此很开心。使用storyboard,我创建了一个带有静态单元格的表格视图控制器,该静态单元格包含允许用户输入的UITextField。用户完成后,我想检索文本字段的内容。

I am having a heck of time with this. Using storyboard, I created a table view controller with a static cell that contains a UITextField to allow for user input. When the user is finished, I want to retrieve the contents of the text field.

这是我做的:


  • 创建 UITableViewCell 的子类名为 SingleLineFieldTableViewCell

  • IBOutlet UITextField * textField; 添加到子类并将其声明为属性(非原子,保留)并合成它。

  • IBOutlet SingleLineFieldTableViewCell * cellNamed; 添加到拥有的表视图控制器,并将其声明为属性(非原子,保留)并合成它。

  • Created a subclass of UITableViewCell named SingleLineFieldTableViewCell
  • Added IBOutlet UITextField *textField; to the subclass and declared it as a property (nonatomic, retain) and synthesized it.
  • Added IBOutlet SingleLineFieldTableViewCell *cellNamed; to the owning table view controller, and declared it as a property (nonatomic, retain) and synthesized it.

在storyboard中,我有一个带静态单元格的表视图控制器。其中一个单元格是自定义单元格,声明为 SingleLineFieldTableViewCell 并拥有 UITextField 。它还被分配了一个单元标识符。

In storyboard, I have a table view controller with static cells. One of the cells is the custom cell, which is declared as SingleLineFieldTableViewCell and owns a UITextField. It is also assigned a cell identifier.

当我跑步时, dequeueReusableCellWithIdentifier 返回 nil 。根据 dequeueReusableCellWithIdentifier RN-AdoptingStoryboards / _index.html#// apple_ref / doc / uid / TP40011297rel =noreferrer>转换为Storyboards发行说明 dequeueReusableCellWithIdentifier:方法返回一个单元格(假设您已经定义了具有给定标识符的单元格)。

When I run, dequeueReusableCellWithIdentifier returns nil. I thought that with Xcode 4 and storyboards, dequeueReusableCellWithIdentifier, according to Converting to Storyboards Release Notes, "The dequeueReusableCellWithIdentifier: method is guaranteed to return a cell (provided that you have defined a cell with the given identifier)".

奇怪的是,当我在Simulatior中运行时,表格按预期显示(部分,单元格大小等),除了我无法编辑自定义单元格。

The weird part is that when I run in the Simulatior, the table appears as expected (section, cell size, etc.), except that I can't edit the custom cell.

我不知所措。任何帮助或想法?

I'm at a loss. Any help or ideas?

- 约翰

推荐答案

我知道这个问题是一年前的问题,但我今天才解决了这个问题。

I know this question was a year ago, but I just went through this problem myself today.

我认为这里的问题是使用静态单元格。

I think the problem here is using static cells.

请参阅Apple文档: http://developer.apple.com/library/ios/#documentation/userexperience/conceptual/tableview_iphone/TableViewCells/TableViewCells.html

See the Apple docs: http://developer.apple.com/library/ios/#documentation/userexperience/conceptual/tableview_iphone/TableViewCells/TableViewCells.html

基本上我的想法是,如果你使用的是静态单元格,则无需使用

Basically the idea is that if you are using static cells then there is no need to use

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath

数据源方法,而只是生成所有的出口UI元素(在静态单元格内)并直接设置它们。

data source method, instead just generate outlets to all your UI elements (inside the static cells) and set them directly.

如果你需要使用此方法,然后您必须将表更改为动态内容模式。

If you need to use this method then you must change the table to dynamic content mode.

这篇关于dequeueReusableCellWithIdentifier使用storyboard静态单元格返回nil的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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