加载.xib文件时访问权限错误

时间:2015-10-05 10:47:03

标签: swift

我对此行super.init(coder: aDecoder)的访问权限不佳。我尝试了很多我在网上找到的解决方案,但它并没有解决它。我使用Swift2.0

import UIKit

class JobsView: UIView {

    // Our custom view from the XIB file
    var view: UIView!

    func xibSetup() {
        view = loadViewFromNib()

        // use bounds not frame or it'll be offset
        view.frame = bounds

        // Make the view stretch with containing view
        view.autoresizingMask = [UIViewAutoresizing.FlexibleWidth, UIViewAutoresizing.FlexibleHeight]
        // Adding custom subview on top of our view (over any custom drawing > see note below)
        addSubview(view)
    }

    func loadViewFromNib() -> UIView {

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

        return view
    }

    override init(frame: CGRect) {
        // 1. setup any properties here

        // 2. call super.init(frame:)
        super.init(frame: frame)

        // 3. Setup view from .xib file
        xibSetup()
    }

    required init?(coder aDecoder: NSCoder) {
        // 1. setup any properties here

        // 2. call super.init(coder:)
        super.init(coder: aDecoder)

        // 3. Setup view from .xib file
        xibSetup()
    }
}

我从这个方法中调用这个Nib

func kolodaViewForCardAtIndex(koloda: KolodaView, index: UInt) -> UIView {
        //return UIImageView(image: UIImage(named: "Card_like_\(index + 1)"))
        return (NSBundle.mainBundle().loadNibNamed("JobsView",owner: self, options: nil)[0] as? UIView)!

    }

0 个答案:

没有答案