为什么会想到使用nib
- 相对于手写UI更方便、快速,界面修改更迅速更直观,产生的bug也少
- 相对storyboard更轻量级,更灵活,针对性也更高,也更方便复用
例子:UITableViewCell通过Nib加载并复用View
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@“example”];
if (!cell) {
[tableView registerNib:[UINib nibWithNibName:@"MyCell" bundle:nil] forCellReuseIdentifier:@"example"];
cell = [tableView dequeueReusableCellWithIdentifier:DASCellIdentifier];
}
然后用nib实现对应的MyCell即可