您的位置:首页 > 其它

xib和Storyboard 创建Cell的方式

2015-04-02 09:27 197 查看
xib 方式
1.在Cell.h文件中加一个宏
#define cellIdentifier @"customCell"

2. ViewController中:
- (void)viewDidLoad {
[super viewDidLoad];

[_tableView registerNib:[UINib     nibWithNibName:cellIdentifierbundle:nil] forCellReuseIdentifier:cellIdentifier];
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
CustomCell *cell = [tableView dequeueReusableCellWithIdentifier:cellIdentifier];

return:cell
}

StoryBoard方式
1.在Cell.h文件中加一个宏
#define cellIdentifier @"customCell"
备注:IB中Identifier 也要填 customCell

2.ViewController
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {

CustomCell *cell = [self.tableView dequeueReusableCellWithIdentifier:CustomCellIdentifier forIndexPath:indexPath];
return cell;
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: