使用xib 自定义cell。
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
InvestViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"investcell"];
if (!cell) {
cell = [[NSBundle mainBundle]loadNibNamed:@"InvestViewCell" owner:nil options:nil].lastObject;
}
return cell;
}
有时候会遇到,模拟器无法显示自定义的cell上得空间。这个时候就shift+command+K,clean一下试试。storyboard定义cell
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"mangecell" forIndexPath:indexPath];
cell.selectionStyle = UITableViewCellSelectionStyleNone;
UIImageView *headerImageView = (UIImageView *)[cell viewWithTag:301];
headerImageView.backgroundColor = [UIColor blueColor];
UILabel *earnLabel = (UILabel *)[cell viewWithTag:302];
earnLabel.text = @"1111";
UILabel *nameLabel = (UILabel *)[cell viewWithTag:303];
nameLabel.text = @"222222";
UILabel *detailLabel = (UILabel *)[cell viewWithTag:304];
detailLabel.text = @"33333";
return cell;
}
这两种方法都要在cell的可视框的右侧设置 identifier。