10

After I have updated to Xcode to 7.3, I found Xcode can't create Xib file, when I create UIView class or UITableViewCell. Does anybody know the reason?

Hasya
  • 9,792
  • 4
  • 31
  • 46
yancey
  • 126
  • 1
  • 6

3 Answers3

10

Very traditional way and existing with any XCode version.

  • Right click on left panel
  • Select new file
  • Select iOS
  • Select User Interface
  • Select Empty then next
  • Give file name.

That will create empty xib, now drag and drop UITableViewCell and give class name as you have given in .h and .m file or swift file name.

enter image description here

Swift class with UITableViewCell

import UIKit

class CustomCell: UITableViewCell {

    @IBOutlet weak var lblName : UILabel!

    override func awakeFromNib() {
        super.awakeFromNib()
        // Initialization code
    }
}
Hasya
  • 9,792
  • 4
  • 31
  • 46
  • 1
    yes, wo know this way to build a new .xib file. But at earier time, Xcode can create .xib file when I create a new UIKIT class file. Has this way be changed in recently Xcode version? – yancey Apr 15 '16 at 01:57
4

Yeah, this is a surprising issue.

  1. First create a nib (e.g. ProfileHeaderView.xib) file from File -> New file.

  2. Then create a .swift (e.g. ProfileHeaderView.swift) file and subclass it from UIView.

  3. Last (but not the least of course), go to Identity Inspector of your .xib file and change the name of class to the name of the created .swift file (e.g. ProfileHeaderView.swift).

Hope that helps.

John Doe
  • 2,173
  • 1
  • 21
  • 12
1

Make sure that you select Cocoa Touch Class in iOS section, rather than OSX's Cocoa Class. That lets you check option Also create XIB File. This works perfectly in Xcode 7.3 for ViewControllers, and any UIView subclasses (e. g. UITableViewCell, UICollectionViewCell)

EDIT: but not for UIView

Igor Kislyuk
  • 330
  • 1
  • 4
  • 14