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