我想在我的 iOS 应用程序的 UITableViewCell
中同时设置 accessoryType
和 accessortyView
,以便让我的用户看到每个单元格中的数据以及移动到详细 View 的指示器,通过使用嵌入在 UILabel
中的我自己的自定义字符串作为 accessoryView
和 UITableViewCellAccessoryDisclosureIndicator
作为 附件类型
。但是,Apple 的 Objective-C 文档暗示我不能在 following line 中同时使用两者。 , 这是我从 this post 借来的:
Discussion
If the value of this property is not nil, the UITableViewCell class uses the given view for the accessory view in the table view’s normal (default) state; it ignores the value of the accessoryType property. The provided accessory view can be a framework-provided control or label or a custom view. The accessory view appears in the right side of the cell.
The accessory view cross-fades between normal and editing states if it set for both states; use the editingAccessoryView property to set the accessory view for the cell during editing mode. If this property is not set for both states, the cell is animated to slide in or out, as necessary.
那么有什么方法可以在我的UITableViewCell
中同时使用accessoryType
和accessortyView
吗?我想实现类似以下的目标,而不是使用 detailTextLabel
来放置我的数据。
[textLabel dataLabel (->)] # this is header just to illustrate my point
[Michael San Francisco (->)]
[Kevin New York (->)]
我刚刚意识到 iOS 默认手机应用程序使用 accessoryView
来显示日期以及 accessoryType
- 这正是我想要做的。
最佳答案
你不应该使用 accessoryView
在 UITableViewCell
中显示附加数据. accessoryView
UITableViewCell
的属性(property)被 Apple 记录为在单元格右侧(正常状态)使用的 View ,通常用作控件。您不需要控件(例如按钮、开关等);听起来你只需要一个 UILabel
.
accessoryView
和 accessoryType
两者都旨在占据 UITableViewCell
中最右边的位置, 用于编辑控件、导航等。
请注意,Apple 提供了几种不同类型的 UITableViewCell
它提供不同数量和外观的文本字段。如果其中一种默认类型不适合您的目的,只需自定义 UITableViewCell
根据需要布局。您可以将您选择的 subview 添加到 UITableViewCell
的 contentView
.这可以在代码或 xib 中完成。
关于ios - 在 iOS 应用程序的 UITableViewCell 中同时设置 accessoryType 和 accessoryView - 可行吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21964946/