Search code examples
iosuitableviewswiftxcode6-beta5

Only Partial tableview cell contents are visible in Xcode_6 beta 5


I am using Xcode 6, Beta 5. Swift language.

My code has viewcontroller with a tableview and a custom tableview cell. There are 3 labels and an imageview in the tableCell.

The problem is: only half of the cell appears. It looks like this:

https://i.sstatic.net/JO4A4.png

https://i.sstatic.net/Ku5Og.png

Here's something interesting I found. Up until XCode 5, the tableviews & viewcontrollers used to be of default size 320x568 in the storyboard.

Now with Xcode 6, Beta 5, the tableviews & viewcontrollers seems to of default size 600x600 in the storyboard

Could this be messing with my layout?

My code is as shown below:

//OrderHistoryDetailViewController

class OrderHistoryDetailViewController: ViewController, UITableViewDataSource, UITableViewDelegate {

@IBOutlet weak var orderPlacedLabel: UILabel!
@IBOutlet weak var orderItemsTableView: UITableView!

override func viewDidLoad() {
    super.viewDidLoad()
}

//MARK: UITableViewDataSource methods

func tableView(tableView: UITableView!, numberOfRowsInSection section: Int) -> Int {
    return 2
}

func tableView(tableView: UITableView!, cellForRowAtIndexPath indexPath: NSIndexPath!) -> UITableViewCell! {
    var orderDetailCell: OrderHistoryDetailCell = tableView.dequeueReusableCellWithIdentifier("OrderDetailCell") as OrderHistoryDetailCell        
    orderDetailCell.priceLabel.text = "$34.89"
    orderDetailCell.quantityOrderedLabel.text = "QTY:1|$34.89 each"
    orderDetailCell.itemOrderedNameLabel.text = "Tooled Leather Laptop Cover"
    orderDetailCell.thumbNailImageView.image = UIImage(named: "laptopCover.png")        
    return orderDetailCell
} 
}

//OrderHistoryDetailCell
class OrderHistoryDetailCell: UITableViewCell {

    @IBOutlet weak var thumbNailImageView: UIImageView!
    @IBOutlet weak var itemOrderedNameLabel: UILabel!
    @IBOutlet weak var quantityOrderedLabel: UILabel!
    @IBOutlet weak var priceLabel: UILabel!
}

Solution

  • New universal iOS8 templates in Xcode 6 come with Size Classes. You can change this default setting in Interface Builder: go to the File Inspector and uncheck "Use size classes". You will then be able to work with iPhone sized view controller scenes (320x568, for example) in one Storyboard and with iPad sized view controller scenes in another Storyboard. However, unless you have a good reason, I discourage you to do so.

    Size Classes (working with their best friend Auto layout) have a lot of advantages. One of them is the fact that you can, in the same view controller scene of a unique Storyboard, define constraints (or fonts or subViews) that will for example only be set for iPhone in portrait mode (compact width / regular height) and other constraints (or fonts or subViews) that will only be set for iPad in landscape mode (regular width / any height).

    Therefore, the 600x600 sized view controller scene you mentioned does not correspond to any particular device but allows you to provide constraints that will fit any screen width and any screen height. You can lean more about Size Classes with the WWDC 2014 video Session 411 "What's new in Interface Builder" (starts at 30 minutes).

    So, in order to answer your question: I think you should keep Size Classes in your project and use auto layout with it. Then, you should check your tableView constraints and your cell's contentView subviews constraints.