Blaszard
Blaszard

Reputation: 31955

Set both accessoryType and accessoryView in UITableViewCell in iOS app - feasible?

I want to set both accessoryType and accessortyView in UITableViewCell in my iOS app, in order to let my users see data in each cell as well as an indicator of moving to the detail view, by using both my own custom string embedded in UILabel as accessoryView and UITableViewCellAccessoryDisclosureIndicator as accessoryType. However, Apple's Objective-C documentation implies that I cannot use both at the same time in the following line, which I borrowed from 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.

So is there any way to use both accessoryType and accessortyView in my UITableViewCell? I'd like to achieve something like the following and not make use of detailTextLabel to put my data on.


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

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

And I just realized iOS default Phone app uses accessoryView to show date as well as accessoryType - which is exactly what I want to do.

Upvotes: 2

Views: 2856

Answers (2)

Daniel
Daniel

Reputation: 9040

Don't believe you can use both. Still a little unclear on exactly what you're trying to do, but you can use any type of control in a custom UITableViewCell. If you are using Storyboards (recommended) then you can drag out any basic control and lay it out as desired. You can use this in combination with an appropriate accessory type.

Upvotes: 0

bneely
bneely

Reputation: 9093

You shouldn't use accessoryView to show additional data in a UITableViewCell. The accessoryView property of UITableViewCell is documented by Apple as a view that is used, typically as a control, on the right side of the cell (normal state). You don't want a control (e.g. a button, switch, etc); it sounds like you simply need a UILabel.

accessoryView and accessoryType are both intended to occupy the rightmost location in a UITableViewCell, for editing controls, navigation, etc.

Note that Apple provides a few different types of UITableViewCell which provide varying numbers, and appearances of, text fields. If one of these default types does not suit your purpose, simply customize the UITableViewCell layout as needed. You can add the subviews of your choice to the UITableViewCell's contentView. This can be done in code or in a xib.

Upvotes: 6

Related Questions