0

After updating to Xcode 8.1 our storyboards and xib are as usual. If we create a new xib/view/storyboard we can't see the freshly added elements in the new view.

Both of these are xib files. The left one is created befor the update, the right one after. You cant see the button eventhough that it is on top of everything and has contrains to fill the view. It also has text content and no sized classes. enter image description here

I know that there are alot questions which explain that this could be sized classes.

why storyboard ui elements not showing on UIViewController in xcode 6?

Storyboard UI Elements not displaying in editor

If we add new elements to it they are directly not visible. Also adding new ViewController to a "old" storyboard it does not show its content if we add elements to it.

What is going on here and how do i solve that?

Community
  • 1
  • 1
bemeyer
  • 6,154
  • 4
  • 36
  • 86

2 Answers2

3

For example, we have TopView (my CustomView):

  1. TopView.xib, set TopView class in File's Owner TopView in Xcode
  2. TopView.swift

 
import UIKit

@IBDesignable class TopView: UIView {

//MARK:- IB Outlets var contentView:UIView? //MARK:- Lifecycle override func awakeFromNib() { super.awakeFromNib() } required init?(coder aDecoder: NSCoder) { super.init(coder: aDecoder) setupThisView() } override init(frame: CGRect) { super.init(frame: frame) setupThisView() } override func prepareForInterfaceBuilder() { super.prepareForInterfaceBuilder() setupThisView() contentView?.prepareForInterfaceBuilder() } //MARK:- Lifecycle methods private func setupThisView(){ guard let view = loadViewFromNib() else { return } view.frame = bounds view.autoresizingMask = [.flexibleWidth, .flexibleHeight] addSubview(view) contentView = view } func loadViewFromNib() -> UIView? { let nibName = String(describing: TopView.self) let bundle = Bundle(for: type(of: self)) let nib = UINib(nibName: nibName, bundle: bundle) return nib.instantiate(withOwner: self,options: nil).first as? UIView } }

3.Add UIView in Storyboard and set the class of the view as TopView Custom class for UIView

If the TopView has not yet appeared in Storyboard then (this happens usually):

  1. Enable Editor -> Automatically Refresh Views
  2. Click on Editor -> Refresh All Views

Still?

  1. Clean the project: ⌘ + K
  2. Build the project ⌘ + B

Result in Storyboard: Storyboard Result of TopView

p.s I just copy this one from my answer here: Custom view (xib) not visible on storyboard

Gent
  • 6,215
  • 1
  • 37
  • 40
-2

1. Open the Xib/Storyboard

2. Select the file attributes tab (on the far left)

file attributes tab

3. click the "opens in" property and change it from Xcode 8 to Xcode 7

opens in property

torinpitchers
  • 1,282
  • 7
  • 13
  • 1
    I'd like to do that, but if i reopen that file it selects code 8.0 again. In addition to that, this answer does not explain why the old Storyboards/xib do work with Xcode 8 selected. – bemeyer Nov 17 '16 at 12:55