ios 7 customizing UITableViewCell's content view

17,107

Solution 1

I was able to do this by doing the following:

  1. Select the cell in the document outline
  2. Change its custom class in the Identity Inspector
  3. Place whatever elements you want into the content view
  4. Connect the IBOutlets to the elements inside the content view using the Connections Inspector

Solution 2

Ok I found an Xcode bug.

If you complete the following this will replicate the issue:
- Create new UIViewController in storyboard
- Drag a UITableView to the VC
- Update the UITableview to have 1(as many) dynamic prototype cells
ISSUE: The cells are added but without a contentView.

RESOLUTION: Rather than updating the amount of cells in the storyboard. Drag a custom cell from the objects part of Xcode, the Cell will be added with a contentView.

Solution 3

I don't really know the answer, but I can suggest work around this issue:

1) Copy existing cell from other tableview to the one you're working on.

2) You will have contentView under your cell now. Design this cell by adding your views.

3) Create a class for your cell, e.g NewCell, then manually create IBOutlet in this class:

@property (nonatomic, strong) IBOutlet UILabel* mainLabel;

4) Assign the cell class in storyboard to the class you just created. After this step, you can drag the outlet from storyboard to class.

I'm not sure if this is a bug for XCode 5 or it is intended, and I'm looking for better solutions as well.

Share:
17,107
giorashc
Author by

giorashc

An enthusiast software engineer who loves designing and implementing solutions for whatever comes through the door.

Updated on June 23, 2022

Comments

  • giorashc
    giorashc almost 2 years

    Using storyboard in ios7 the content view is explicitly viewed under the Table View Cell in the story board editor (opposed to previous versions where it was hidden from the interface).

    The problem is that I cannot connect the cell's custom elements to my custom cell's ib outlets anymore (subclass of UITableCellView) and can only connect them to the table's content view (UIView) which CANNOT be customized (i.e. its custom class attribute is grayed)

    This leaves me with the option to use tags which I find inconvenient and less elegant.

    I could also create a custom view in a xib, do all the connections and then manually add this custom view as the content view of the table but I am looking for a way doing it via the story board editor.

    Is there a way to connect UI elements to a custom cell's content view in the story board editor in ios7 ?