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?
Very traditional way and existing with any XCode version.
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.
Swift class with UITableViewCell
import UIKit
class CustomCell: UITableViewCell {
@IBOutlet weak var lblName : UILabel!
override func awakeFromNib() {
super.awakeFromNib()
// Initialization code
}
}
Yeah, this is a surprising issue.
First create a nib (eg ProfileHeaderView.xib) file from File -> New file.
Then create a .swift (eg ProfileHeaderView.swift) file and subclass it from UIView.
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 (eg ProfileHeaderView.swift).
Hope that helps.
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 (eg UITableViewCell, UICollectionViewCell)
EDIT: but not for UIView
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.