#pragma mark - 数据源方法
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
return self.heros.count;
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
UITableViewCell *cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleValue2 reuseIdentifier:nil];
// 取出模型
MJHero *hero = self.heros[indexPath.row];
// 设置cell的数据(部分属性是需要根据cell的类型来显示的)
cell.textLabel.text = hero.name;
cell.detailTextLabel.text = hero.intro;
cell.imageView.image = [UIImage imageNamed:hero.icon];
// 设置cell右边指示器的类型(箭头、对号。。。)
// if (indexPath.row % 2 == 0) {
cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
// }
// cell.accessoryType = UITableViewCellAccessoryDetailDisclosureButton;
// cell.accessoryView = [[UISwitch alloc] init];
// 设置背景(背景view不用设置尺寸, backgroundView的优先级 > backgroundColor)
UIImageView *bgView = [[UIImageView alloc] init];
bgView.image = [UIImage imageNamed:@"buttondelete"];
// bgView.backgroundColor = [UIColor redColor];
cell.backgroundView = bgView;
UIView *selectedbgView = [[UIView alloc] init];
selectedbgView.backgroundColor = [UIColor greenColor];
cell.selectedBackgroundView = selectedbgView;
return cell;
}
UI基础-iOS黑马-UITableViewCell的常见属性3-LoLdemo
最新推荐文章于 2015-01-09 21:51:23 发布