在自定义cell的情况下,dequeueReusableCellWithIdentifier:方法获取的cell可能为空,需要代码判断,手动加载cell的xib文件。而dequeueReusableCellWithIdentifier: forIndexPath: 方法获取的cell不会为空。使用步骤为:
1.在tableView初始化时,向tableView注册重用identifier
[_tableView registerNib:[UINib nibWithNibName:@"MyCell" bundle:[NSBundle mainBundle]] forCellReuseIdentifier:@"my cell"];
2.在代理方法tableView:cellForRowAtIndexPath:中,利用identifier获取cell
MyCell *cell = (MyCell *)[tableView dequeueReusableCellWithIdentifier:@"my cell" forIndexPath:indexPath];