简体   繁体   English

设置样式分组表

[英]Settings-style grouped table

So it's trivial to create a Settings style table on the iPhone. 因此,在iPhone上创建一个设置样式表是微不足道的。 The problem is, they add a great deal of code as your Settings have a gamut of options/styled cells. 问题是,他们添加了大量代码,因为您的设置有多个选项/样式单元格。 One section might have a check list, another might have cells with accessory disclosures to drill down further, another might be labels with UITextFields. 一个部分可能有一个检查列表,另一个部分可能有附件披露的单元格可以进一步向下钻取,另一个可能是具有UITextFields的标签。

My question here is, what's the cleanest way to go about creating this table. 我的问题是,创建此表的最简洁方法是什么。 Do you typically create a subclass of UITableViewController and then subclass UITableViewCell for each different type of cells, and write supporting classes for those cells? 您是否通常创建UITableViewController的子类,然后为每种不同类型的单元子类化UITableViewCell,并为这些单元格编写支持类? Meaning if you have a Settings style table with 4 sections, all different types of cells, you will load 4 nibs into the table and import 4 class files? 这意味着如果您有一个包含4个部分的设置样式表,所有不同类型的单元格,您将在表中加载4个笔尖并导入4个类文件? Programmatically set the frame, views, textfields and tag them for later access? 以编程方式设置框架,视图,文本字段并标记它们以供以后访问?

The answer(s) to this is probably subjective, but I'd like to know what you experts consider the most elegant approach to this common problem. 对此的答案可能是主观的,但我想知道你的专家认为这个常见问题最优雅的方法。

The easiest way to do this is to simply add your controls during the tableView:cellForRowAtIndexPath: method. 最简单的方法是在tableView:cellForRowAtIndexPath:方法中简单地添加控件。

I also recommend this to help corral your code: A technique for using UITableView and retaining your sanity 我还建议这样做以帮助您编写代码: 使用UITableView并保持理智的技巧

I would rather set most of the settings that I can in Interface Builder, instead of writing a whole bunch of code to make the visual/layout just right. 我宁愿在Interface Builder中设置大部分设置,而不是编写一大堆代码来使视觉/布局恰到好处。 As you can imagine, it will take quite a few rounds of "modify - build - test" in the iPhone Simulator to get this special table view laid out the way you want it. 您可以想象,在iPhone模拟器中需要进行相当多的“修改 - 构建 - 测试”才能获得您想要的特殊表格视图。

I feel it's probably a bit easier to do all of these rough visual changes in IB, then load all of the custom UITableViewCell dynamically via their identifiers in code. 我觉得在IB中完成所有这些粗略的视觉变化可能要容易一些,然后通过代码中的标识符动态加载所有自定义UITableViewCell You could then do one final round of tweaking on this code, if something that you want is not doable in IB. 如果您想要的东西在IB中不可行,那么您可以对此代码进行最后一轮调整。

Three20 library (extracted from Facebook iPhone app) has a set of ready-made cells that contain various controls. Three20库(从Facebook iPhone应用程序中提取)具有一组包含各种控件的现成单元格。

(Not sure you want to use them, however. Three20 suffers from “not-invented-here” a little bit and tries to subclass and extend everything, so adding it adds quite a bit of a mess to your project. But at least you can use it as an example.) (不确定你是否想要使用它们.Tanning20遭受了“not-invented-here”一点点的困扰并尝试子类化并扩展所有内容,所以添加它会给你的项目增加一些混乱。但至少你可以用它作为例子。)

PS Your question inspired me to open a “ What are your favourite UITableView / UITableViewCell tricks? PS你的问题激励我打开一个“ 你最喜欢的UITableView / UITableViewCell技巧是什么? ” thread on Stack Overflow, check it out for more tips. “Stack Overflow上的线程,请查看更多提示。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM