如何在Xcode中使用主详细信息视图创建自定义原型单元? [英] How do you create a custom prototype cell with master detail view in Xcode?

查看:84
本文介绍了如何在Xcode中使用主详细信息视图创建自定义原型单元?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用主详细信息模板创建了一个xcode项目.我想自定义单元格以将数据放入2个单独的标签中.我尝试在情节提要编辑器中自定义单元,但似乎单元上的所有内容都已锁定在适当的位置.我可以以编程方式或在情节提要编辑器中创建自定义单元.我知道我可以将默认textLabel上的文本设置为空白,然后以编程方式创建其他标签,但这似乎不需要在每个单元格的中间都随机有一个空的textLabel.因此,我想知道是否有一种方法可以在情节提要编辑器中编辑单元格,删除默认的textLabel或将textLabel的大小和位置重新定位到需要的位置.

I created an xcode project with the master detail template. I want to customize the cell to put my data into 2 separate labels. I tried customizing the cell in the storyboard editor, but it seems like all of the stuff on the cell is locked in place. I am fine either creating the custom cell programmatically or in the storyboard editor. I know I could just set the text on the default textLabel to blank and then create the other labels programmatically, but that doesn't seem very need to just have a random empty textLabel in the middle of every cell. So I am wondering if there is a way to edit the cell in storyboard editor, delete the default textLabel, or resize and reposition the textLabel to where I need it to go.

非常感谢您的帮助.

谢谢.

推荐答案

这是标准做法.只需忽略内置的textLabel并完成它即可.默认情况下,标签始终为空白.它是在代码中设置的.

That's standard practice. Just ignore the built in textLabel and be done with it. By default the label is blank anyway. It's set in code.

要访问新标签等,请为自定义单元格创建一个新的自定义类(XCode中的File | New | File ... | Objective-C类),为其指定名称,并为子类选择UITableViewCell.最后,在Interface Builder中用于自定义单元的Identity Inspector上,为自定义类"选择该新类.

To access new labels and such, create a new custom class for the custom cell (File|New|File...|Objective-C Class in XCode), give it a name and for the subclass choose UITableViewCell. Finally, on the Identity Inspector for the custom cell in Interface Builder, choose that new class for the Custom Class.

现在,从XCode的助理编辑器"中,您可以CTRL-拖动新标签,并拖动到新的自定义单元格类的.h文件中,以创建IBOutlet属性.

Now, from the Assistant Editor in XCode, you can CTRL-drag new labels and such to the .h file of the new custom cell class to create IBOutlet properties.

请确保在属性检查器"选项卡上为该单元格设置单元格标识符,并在代码中引用该单元格,尤其是在cellForRowAtIndexPath中.

Be sure to set the cell Identifier on the Attributes Inspector tab for the cell and reference that in your code, especially in cellForRowAtIndexPath.

将自定义单元格类的.h文件导入视图控制器的.h文件中,然后将该单元格强制转换为cellForRowAtIndexPath中的自定义单元格类,以访问新属性或将定义UITableViewCell *cell =更改为新类,如MyTableViewCell *cell =.

Import the custom cell class's .h file in the view controller's .h file, then cast the cell to your custom cell class in cellForRowAtIndexPath to access the new properties or change the definition UITableViewCell *cell = to your new class like MyTableViewCell *cell =.

这篇关于如何在Xcode中使用主详细信息视图创建自定义原型单元?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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