ios 7 customizing UITableViewCell's content view

前端 未结 5 636
春和景丽
春和景丽 2021-02-11 00:59

Using storyboard in ios7 the content view is explicitly viewed under the Table View Cell in the story board editor (opposed to previous version

相关标签:
5条回答
  • 2021-02-11 01:37

    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.

    0 讨论(0)
  • 2021-02-11 01:46

    I might be duplicating someone else's answer but I found this workaround which helped bypass this silly XCode bug. Short solution: When you build your custom cell in Storyboard, do NOT drag your UI elements inside the cell or content view.

    Instead, drag them OUTSIDE so that they're child elements of the parent table view!

    It's easiest to do this drag and drop if you use the little hierarchy menu on the left to make sure your elements wind up in the right spot.

    Once the elements are dragged in, just control-click and drag from the custom cell to the UI elements to make your connections. Woo hoo!

    Once your connections are set, then (finally) drag the UI elements back INTO the custom cell's content view and lay them out as you normally would.

    UPDATE: While my method works, look for a comment by thomasdao in an answer below where he just drags the connections directly into the .h file (the little circles in the left margin where you declare your IBOutlets) -- this is actually the easiest solution but unfortunately it's stuck as a comment.

    0 讨论(0)
  • 2021-02-11 01:53

    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.

    0 讨论(0)
  • 2021-02-11 01:58

    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
    0 讨论(0)
  • 2021-02-11 02:03

    Create new uiviewcontroller with xib interface and add the required sub-views .Also,establish the iboutlet connections.

    Now ,rename the viewcontroller : UIViewcontroller to viewcontroller : UITableviewcell in .h file of your newly created view controller.

    Your tableviewcell was created and ready to use with any UITableview of any class.

    Hope it helps.

    0 讨论(0)
提交回复
热议问题