为TableView部分iOS添加背景

时间:2017-08-31 04:25:17

标签: ios objective-c uitableview background-image sections

我有一个动态多行的部分,我需要将所有部分与背景分开,如下图所示。

特别是所有部分的边界线。皮斯让我知道如何才能实现。

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView;
{
    return  ProductArray.count;  
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    NSArray *arr = [ProductArray objectAtIndex:section];
    return arr.count;    
}

请参阅此

image

我尝试添加页眉和页脚,但我不明白如何为整个部分添加矩形框图像。

2 个答案:

答案 0 :(得分:0)

在该视图的出口后将视图放入您的单元格中。并使用 cellForRowAtIndexPath 这种方法。

    - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
 {
    TableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"TableViewCell" forIndexPath:indexPath];
                [cell setSelectionStyle:UITableViewCellSelectionStyleNone];

    cell.viewBackGround.backgroundColor = [UIColor redColor];
    return cell;
}

答案 1 :(得分:0)

对于上述要求,我想建议您采用以下方法。

只创建一个包含多行的部分。

  1. UITableView的每一行都有UITableViewCell
  2. UITableViewCell内创建我们要添加边框的内容视图
  3. UITableViewCell的每一行都有另一个UITableView(内部内容视图),其方法由UITableViewCell个单元格处理
  4. 根据行数更改UITableView(内部)高度。
  5. 根据行数+ orderID标题提供UITableViewCell的高度。
相关问题