-
建cell文件,继承UITableViewCell
-
如果你没使用xib或者storyboard的话可以在直接new一个cell,跟普通写法一样
static NSString *cellid = @"cellIdentifier";
TableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:cellid];
if (!cell) {
cell = [[TableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellid];
}
3. 如果有xib
static NSString *CellIdentifier = @"FriendCell";
FriendCell *cell= [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (!cell) {
[tableView registerNib:[UINib nibWithNibName:@"FriendCell" bundle:nil] forCellReuseIdentifier:CellIdentifier];
cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
}
4.还有个未必好的办法(这个办法也用于在xib多个view中获取到想要的一个)
static NSString *reuseId = @"headCell";
NADHeadArticleCell *cell = [tableView dequeueReusableCellWithIdentifier:reuseId];
if (!cell) {
NSArray *nib = [[NSBundle mainBundle]loadNibNamed:@"NADHeadArticleCell" owner:self options:nil];
for(id oneObject in nib){
if([oneObject isKindOfClass:[NADHeadArticleCell class]]){
cell = (NADHeadArticleCell *)oneObject;
break;
}
}
}