xib和Storyboard 创建Cell的方式

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; }

 

posted @ 2015-04-02 09:27  菜鸟程序猿  阅读(349)  评论(0编辑  收藏  举报