UITableView 使用
2018-11-07 本文已影响2人
啵啵_long_港
UITableView 取消点击cell的选中颜色
cell.selectionStyle = UITableViewCellSelectionStyleNone;
UITableView 去掉cell分割线
_tableView.separatorStyle = UITableViewCellSeparatorStyleNone;
UITableView 设置默认背景颜色灰色为白色
_tableView.backgroundColor = [UIColor whiteColor];
UITableView 设置xib自定义cell
注意:MyTableViewCell为xib文件名(loadNibNamed:@"MyTableViewCell")
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
MyTableViewCell *cell = (MyTableViewCell *)[tableView dequeueReusableCellWithIdentifier:@"MyTableViewCell"];
if(nil == cell) {
NSArray *nib = [[NSBundle mainBundle] loadNibNamed:@"MyTableViewCell" owner:self options:nil];
cell = [nib objectAtIndex:0];
}
return cell;
}
UITableView去掉header
- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section
{
return 0.0;
}
- (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section
{
UITableViewHeaderFooterView *header = [tableView dequeueReusableHeaderFooterViewWithIdentifier:@"header"];
if (header == nil) {
header = [[UITableViewHeaderFooterView alloc] initWithReuseIdentifier:@"header"];
UIView *view = [[UIView alloc] initWithFrame:CGRectMake(0, 5, screenWidth, 1)];
view.backgroundColor = [UIColor whiteColor];
[header addSubview:view];
}
return header;
}