实例化TableCell 在设置delegate之前注册xib Swift self.tableView.registerNib(UINib.init(nibName: "ImageLabelTableViewCell ", bundle: nil), forCellReuseIdentifier: "ImageLabelTableViewCell"); Swift3 self.tableView.register(UINib.init IndexTableViewCell", bundle: nil), forCellReuseIdentifier: "IndexTableViewCell"); OC [self.tableView registerNib:[UINib RenwuMyViewController" bundle:nil]; 实例化UICollectionCell 在设置delegate之前注册xib Swift self.collectionView.registerNib(UINib.init MyCell", bundle: nil), forCellWithReuseIdentifier: "MyCell"); Objc [self.collectionView registerNib:[UINib
SubscribeFooter.self, ofKind: UICollectionView.elementKindSectionFooter) 我换成原生的注册 collectionView.register(UINib UICollectionView.elementKindSectionHeader, withReuseIdentifier: "SubscribeHeader") collectionView.register(UINib
UICollectionViewDataSource,UICollectionViewDelegateFlowLayout 设置 Swift self.collectionView.register(UINib.init nonatomic) NSMutableArray<NSMutableArray<OrderPicModel *> *> *tableData; [self.collectionView registerNib:[UINib super.awakeFromNib() // Initialization code } } 注册 self.collectionView.registerNib(UINib right3Y, itemWidth, itemHeight2) } return attribute } } 设置 collectionView.registerNib(UINib.init MainBigCollectionViewCell", bundle: nil), forCellWithReuseIdentifier: "mainBigCollCell"); collectionView.registerNib(UINib.init
其实这是一个很简单的过程,关键代码也就包括下面的两部分: //注册集合视图单元格 UINib *nib = [UINib nibWithNibName:@"MyCollectionCell"
既可以与 UIView 关联,也可以与 UIViewController 关联,也可以同时关联 UIView 与 UIViewController 使用 xib 通过 Bundle 方式加载 通过 UINib UIView view.addSubview(testView) UINib NS_CLASS_AVAILABLE_IOS(4_0) @interface UINib : NSObject // If in response to memory pressure (e.g. memory warning), reloading from the bundle when necessary. + (UINib = nil) -> [Any] } UINib Demo let testViewNib = UINib.init(nibName: "TestView", bundle: Bundle.main) func loadTestView() { let testView = UINib.instantiate(withOwner: nil, options: nil)[0] as!
collectionView.autoresizingMask = [.flexibleHeight, .flexibleWidth] collectionView.register(UINib CollectionNormalCell", bundle: nil), forCellWithReuseIdentifier: NormalCellID) collectionView.register(UINib CollectionPrettyCell", bundle: nil), forCellWithReuseIdentifier: PrettyCellID) collectionView.register(UINib
var bundle: NSBundle = NSBundle.mainBundle() var nib: UINib = UINib(nibName: "Cell", bundle: bundle func registerCell() { var bundle: NSBundle = NSBundle.mainBundle() var nib: UINib = UINib(nibName: "Cell", bundle: bundle) tableView.registerNib(nib, forCellReuseIdentifier:
collectionView.autoresizingMask = [.flexibleHeight, .flexibleWidth] collectionView.register(UINib CollectionNormalCell", bundle: nil), forCellWithReuseIdentifier: NormalCellID) collectionView.register(UINib CollectionPrettyCell", bundle: nil), forCellWithReuseIdentifier: PrettyCellID) collectionView.register(UINib
NSString * 是 xib 文件名 * NSBundle * 传入 mainBundle * 如果传入参数是 mainBundle 则可以传入 nil * */ UINib *nib = [UINib nibWithNibName:<#(NSString *)#> bundle:<#(NSBundle *)#>] xib 和 storyboard 对比 共同点 都用来描述软件界面
mainBundle]loadNibNamed:NSStringFromClass(self) owner:nil options:nil] ; return xibArray[0]; 第二种加载方式 UINib *nib = [UINib nibWithNibName:NSStringFromClass(self) bundle:nil]; NSArray *xibArray = [nib instantiateWithOwner
details/102794333 Xcode11 版本,通过xib创建UICollectionReusableView,存在无法获取xib文件问题 使用流程: 注册xib let nibfoot = UINib.init
MyCustomCell: UITableViewCell, Reusable { } 接着在tableview或者collectionView中register tableView.register(UINib.init
8 UINib *headerNib = [UINib nibWithNibName: @"CollectionHeaderReusableView" 9 withReuseIdentifier: @"CollectionHeaderReusableView"]; 15 16 17 //注册FooterView 18 UINib *footerNib = [UINib nibWithNibName: @"CollectionFooterReusableView" 19
imageWithContentsOfFile:[dyBundle pathForResource:@"test" ofType:@"png"]]; [self.tableView registerNib:[UINib EmbededFramework.framework/EmViewController" bundle:[NSBundle mainBundle]]; [self.tableView registerNib:[UINib
UINib *headerNib = [UINib nibWithNibName: @"CollectionHeaderReusableView" withReuseIdentifier: @"CollectionHeaderReusableView"]; //注册FooterView UINib *footerNib = [UINib nibWithNibName: @"CollectionFooterReusableView"
= self; collection.delegate = self; collection.prefetchDataSource = self; //注册Cell UINib *nib = [UINib nibWithNibName:@"ImgCollectionViewCell" bundle:nil]; [collection registerNib:nib forCellWithReuseIdentifier
nibsRegistered) { 19 UINib *nib=[UINib nibWithNibName:@"SlideBarCell" bundle:nil]; 20
let cellNib = UINib(nibName: "carTblCell", bundle: nil) tableView.registerNib(cellNib, forCellReuseIdentifier
做了内存优化"如果内存紧张"内存警告,可以自动释放,如果有需要会重新自动加载"" //第一个参数:XIB的名字 //第二个参数:Bundle 名,如果传入 nil,会自动从 mainBundle 获取 UINib *nib = [UINib nibWithNibName:@"CZAppView" bundle:nil]; //第一个、第二个参数,老师没有讲,说自己从来没有用过。
/// 注册 xib cell func register<T: UITableViewCell>(nib cellType: T.Type) { register(UINib