之前没有用过storyboard,现在到了iOS8基本上storyboard已经主导了开发手段
今天使用了一下,在创建tableview的时候碰到了一些问题,在这里分享下
在storyboard中拖cell,很简单
只需要修改下拖动cell的类型,然后设置下 reuse identifier
之后在代码中
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
DownloadBookCell *cell = [tableView dequeueReusableCellWithIdentifier:@"cell" forIndexPath:indexPath];
if (!cell) {
cell = [[DownloadBookCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"DownloadBookCell"];
}
return cell;
}
即可完成,看下图
让我比较郁闷的是,我最开始使用的是xib,一直配合
<span style="font-size:18px;"> [self.tableView registerClass:NSClassFromString(@"DownloadBookCell") forCellReuseIdentifier:@"cell"];
</span>
,结果导致的就是我在storyboard上拖得cell一只加载不出来。
现在想想,是因为我有注册了一个新的cell,这个cell不是经过xib加载生成的,所以是空的,哈哈
到这里应该就清楚了,使用storyboard 和 register + layout 都可以为tableview生成复用cell。