如何在UITableView中进行就地编辑? [英] How to do edit-in-place in a UITableView?

查看:124
本文介绍了如何在UITableView中进行就地编辑?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否有标准的方法来设置允许编辑的表格,如下所示:

Is there a standard way to set up a table to allow editing-in-place, kind of like this:

我目前只需要可编辑的文本,但我可能需要UISwitches或未来的UISliders。

I only need editable text at the moment, but I might need UISwitches or UISliders in the future.

推荐答案

是的。只需添加 UITextField ,其字体 textColor 设置适当的值,作为表格单元格的 contentView 的子视图。你可能想给字段一个标签,这样你就可以使用 contentView 's -viewWithTag:方法。

Yep. Just add a UITextField, with its font and textColor set to appropriate values, as subviews of the table cell's contentView. You probably want to give the field a tag as well, so that you can easily grab a reference to it using the contentView's -viewWithTag: method.

使用短格式,您可以保留一系列单元格,每个字段一个,并将它们交给表视图,而不通过 -dequeueReusableCellWithIdentifier:机制,但如果你有很多东西要输入那么它会得到更复杂。在这种情况下,您可能希望为每种类型的单元格分配不同的重用标识符 - 一个用于文本字段单元格,一个用于切换单元格,一个用于滑块单元格等。一旦您出列或创建了行的单元格,然后从内容视图中获取其控件(如上所示),并从存储该值的任何位置设置其值。

With short forms you can get away with keeping an array of cells, one for each field, and handing them off to the table view without going through the -dequeueReusableCellWithIdentifier: mechanism, but if you've got a lot of stuff to enter then it gets more complicated. In that case, you probably want to assign a different reuse identifier to each type of cell—one for text-field cells, one for switch cells, one for slider cells, etc. Once you've dequeued or created the row's cell, you'd then grab its control from the content view (as above) and set its value from wherever you've stored that.

这篇关于如何在UITableView中进行就地编辑?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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