ios - 在 iOS 应用程序的 UITableViewCell 中同时设置 accessoryType 和 accessoryView - 可行吗?

标签 ios objective-c uitableview

我想在我的 iOS 应用程序的 UITableViewCell 中同时设置 accessoryTypeaccessortyView,以便让我的用户看到每个单元格中的数据以及移动到详细 View 的指示器,通过使用嵌入在 UILabel 中的我自己的自定义字符串作为 accessoryViewUITableViewCellAccessoryDisclosureIndicator 作为 附件类型。但是,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 中同时使用accessoryTypeaccessortyView 吗?我想实现类似以下的目标,而不是使用 detailTextLabel 来放置我的数据。


[textLabel    dataLabel    (->)] # this is header just to illustrate my point

[Michael    San Francisco  (->)]
[Kevin      New York       (->)]

我刚刚意识到 iOS 默认手机应用程序使用 accessoryView 来显示日期以及 accessoryType - 这正是我想要做的。

最佳答案

你不应该使用 accessoryViewUITableViewCell 中显示附加数据. accessoryView UITableViewCell的属性(property)被 Apple 记录为在单元格右侧(正常状态)使用的 View ,通常用作控件。您不需要控件(例如按钮、开关等);听起来你只需要一个 UILabel .

accessoryViewaccessoryType两者都旨在占据 UITableViewCell 中最右边的位置, 用于编辑控件、导航等。

请注意,Apple 提供了几种不同类型的 UITableViewCell它提供不同数量和外观的文本字段。如果其中一种默认类型不适合您的目的,只需自定义 UITableViewCell根据需要布局。您可以将您选择的 subview 添加到 UITableViewCellcontentView .这可以在代码或 xib 中完成。

关于ios - 在 iOS 应用程序的 UITableViewCell 中同时设置 accessoryType 和 accessoryView - 可行吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21964946/

相关文章:

javascript - jQuery $ ('parent > *' ) 选择器和带有点击委托(delegate)的 iOS

iphone - 错误实例方法-initwithFrame :imageName:imgname not found Objective-C

ios - 如果新的iOS版本引入了可能的类冲突(与我的前缀相同的Apple类),我该怎么办?

ios - 行高不会自动更新

ios - 使用自动布局将 UIButton 添加到自定义单元格

ios - 地理编码不返回邮政编码

objective-c - 在屏幕中间画一个方形边框

objective-c - 不能从捕获上下文的局部函数形成 C 函数指针

swift - UITableView - 获取关于滚动的通知

ios - 如何在swift 2的tableview中显示特定图像