Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Xcode 7.3 can't create xib with for UIView / UITableViewCell together

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?

like image 413
yancey Avatar asked Apr 14 '16 10:04

yancey


People also ask

What is difference between XIB and NIB?

NIBs and XIBs are effectively the same thing: XIBs are newer and are used while you're developing, whereas NIBs are what get produced when you create a build. In modern versions of iOS and macOS, NIBs and XIBs have effectively been replaced by storyboards, although you may still meet them if you work on older projects.

How do you duplicate XIB?

The best way to do this is use cmd ⌘ ,shift, s on the xib or storyboard. Then save it with a new name or location. This is the easiest way to do it, and also the safest, I reckon. Note this is the Duplicate option under the File menu.

What is an XIB file in Xcode?

What are XIB files? From the point of view of the UI designer, XIB files contain the views or windows that you design in Interface Builder – the controls, their layout and properties, and their connections to your code. It is important to understand that on a technical level, XIB files are stored object graphs.


3 Answers

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.

like image 121
John Doe Avatar answered Nov 15 '22 23:11

John Doe


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
    }
}
like image 42
Hasya Avatar answered Nov 16 '22 00:11

Hasya


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

like image 32
Igor Kislyuk Avatar answered Nov 16 '22 00:11

Igor Kislyuk