实例化TableCell
在设置delegate之前注册xib
Swift
代码语言:javascript复制self.tableView.registerNib(UINib.init(nibName: "ImageLabelTableViewCell", bundle: nil), forCellReuseIdentifier: "ImageLabelTableViewCell");Swift3
代码语言:javascript复制self.tableView.register(UINib.init(nibName: "IndexTableViewCell", bundle: nil), forCellReuseIdentifier: "IndexTableViewCell");OC
代码语言:javascript复制[self.tableView registerNib:[UINib nibWithNibName:@"ImageLabelTableViewCell" bundle:nil] forCellReuseIdentifier:@"ImageLabelTableViewCell"];实例化Cell
Swift
代码语言:javascript复制let cell = tableView.dequeueReusableCellWithIdentifier("ImageLabelTableViewCell", forIndexPath: indexPath) as! ImageLabelTableViewCell;Swift3
代码语言:javascript复制let cell = tableView.dequeueReusableCell(withIdentifier: "IndexTableViewCell", for: indexPath) as! IndexTableViewCell;OC
代码语言:javascript复制ImageLabelTableViewCell *cell = [self.tableView dequeueReusableCellWithIdentifier:@"ImageLabelTableViewCell" forIndexPath:indexPath];如果用的storybord中的tableview的cell直接用dequeueReusableCellWithIdentifier方法就行了
注意dequeueReusableCellWithIdentifier方法是从已经实例化的cell中查找id为textLeftCell的对象并进行拷贝
实例化视图控制器
从storyboard中
Swift
代码语言:javascript复制self.storyboard?.instantiateViewControllerWithIdentifier("renwuMy") as! RenwuMyViewController;根据xib实例化控制器
代码语言:javascript复制RenwuMyViewController * renwuMy Controller = [[RenwuMyViewController alloc] initWithNibName:@"RenwuMyViewController" bundle:nil];实例化UICollectionCell
在设置delegate之前注册xib
Swift
代码语言:javascript复制self.collectionView.registerNib(UINib.init(nibName: "MyCell", bundle: nil), forCellWithReuseIdentifier: "MyCell");Objc
代码语言:javascript复制[self.collectionView registerNib:[UINib nibWithNibName:@"MyCell" bundle:nil] forCellWithReuseIdentifier:@"MyCell"];实例化Cell
Swift
代码语言:javascript复制let cell = self.collectionView.dequeueReusableCellWithReuseIdentifier("MyCell", forIndexPath: indexPath) as! MyCell;OC
代码语言:javascript复制MyCell *cell = [self.collectionView dequeueReusableCellWithReuseIdentifier:@"MyCell" forIndexPath:indexPath];从xib中实例化对象
代码语言:javascript复制let cell = NSBundle.mainBundle().loadNibNamed("FuImageLabelTableViewCell", owner: self, options: nil).first as! FuImageLabelTableViewCell;


