IBDesignable never finishes updating UITableViewCell in storyboard
Asked Answered
N

3

12

This is a similar question to this but not quite the same.

I have created a subclass of UITableViewCell which references a custom nib and marked it as @IBDesignable. Changes that are made both in code and from the .xib file display correctly in the simulator and on a device but not in the storyboard.

import UIKit

@IBDesignable class TextFieldTableViewCell: UITableViewCell {

    var view: UIView!

    required init?(coder aDecoder: NSCoder) {
        super.init(coder: aDecoder)

        setup()
    }

    override init(style: UITableViewCellStyle, reuseIdentifier: String?) {
        super.init(style: style, reuseIdentifier: reuseIdentifier)

        setup()
    }

    func setup() {
        view = loadViewFromNib()
        view.frame = bounds
        view.autoresizingMask = [UIViewAutoresizing.FlexibleWidth, UIViewAutoresizing.FlexibleHeight]
        contentView.addSubview(view)
    }

    func loadViewFromNib() -> UIView {

        let bundle = NSBundle(forClass: self.dynamicType)
        let nib = UINib(nibName: "TextFieldTableView", bundle: bundle)
        let view = nib.instantiateWithOwner(self, options: nil)[0] as! UIView

        return view
    }
}

The storyboard displays a permanent "Designables Updating".

Designables Updating

Breaking the problem down into a less complex test of only subclassing a UITableViewCell and marking it as @IBDesignable results in the same permanent "Designables Updating".

import UIKit

@IBDesignable class TextFieldTableViewCell: UITableViewCell {

    required init?(coder aDecoder: NSCoder) {
        super.init(coder: aDecoder)
    }

    override init(style: UITableViewCellStyle, reuseIdentifier: String?) {
        super.init(style: style, reuseIdentifier: reuseIdentifier)
    }

}

Has anyone had success with creating a @IBDesignable UITableViewCell subclass? This is happening in Xcode 7 beta 6 and beta 5.

Nies answered 26/8, 2015 at 1:37 Comment(4)
I am facing the same issue. But when I put tableViewCell in a normal ViewController, i can do the IBDesignable. So, I believe it is an XCode bug that cell cannot be designable in TableViewImpenetrable
Apple has responded to a bug report I've submitted and it is indeed a bug.Nies
Thanks, helps a lotImpenetrable
I am using Xcode 9 GM. It does not have this issue.Lusitania
N
6

This issue has been resolved as of Xcode 9.

I had reported this issue to Apple and at least have the piece of mind knowing that this is a known bug. It is currently an open issue under the problem ID 17973876.

Edit: As of 12/7/2016 this bug is still marked as open.

Nies answered 8/3, 2016 at 18:13 Comment(2)
This is currently happening to me on XCode9? Should I also be looking to report the issue to them as well?Monochord
I just placed a UICollectionView in my Custom UIView and it's also not rendering in the Storyboard. I am just confused is the issue on my end or it's a bug.!Zoology
R
1

I was having similar problems. This thread helped me understand the issue: Is there a way for Interface Builder to render IBDesignable views which don't override drawRect:

I got it to work by adding

override init(style: UITableViewCellStyle, reuseIdentifier: String?) {
        super.init(style: style, reuseIdentifier: reuseIdentifier)
        layoutSubviews()
    }

as far as i understand after reading the above stack link, IBDesignable loads the nib in storyboard not from nib or from coder but from the init with frame. Not too sure but I think init with style is doing a similar thing.

Reinhart answered 8/9, 2015 at 15:49 Comment(3)
Adding the above suggested code doesn't provide any difference.Nies
are you overiding the layoutSubviews() method and calling super? I had some custom drawing code I needed and so implemented the method. I find xib really fiddly to work with, but that might make the difference. >override func layoutSubviews() { super.layoutSubviews() }Reinhart
I've got the same problem with XCode 7.2, and this didn't help. I also don't see how implementing layoutSubviews and just calling the superclass version can help - when layoutSubviews is called it'll just invoke the superclass version automatically if it's not overridden.Homothallic
C
0

It seems that the "Updating" bug is happening only when the cell is inside a storyboard. Everything works OK when you create special .xib file just for the cell.

Hopefully, they will fix it soon.

Calefacient answered 13/6, 2016 at 10:46 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.