【问题标题】:How to set different Background Image For Grouped Table Section..?如何为分组表部分设置不同的背景图像..?
【发布时间】:2013-12-26 13:25:34
【问题描述】:

您好,我正在尝试为分组表视图部分的背景设置图像(不适用于部分标题),我正在使用以下代码:-

-(void)addBackgroundViewForSectionIndex:(int)tagIndex {

    for (UIView * subview in tbl_home.subviews) {
        if(subview.tag == tagIndex)
            [subview removeFromSuperview];
    }

    CGRect sectionFrame = [tbl_home rectForSection:tagIndex];
    UIImageView *newView = [[UIImageView alloc]initWithFrame:sectionFrame];
    newView.tag = tagIndex;
    [newView setImage:[UIImage imageNamed:@"Section@2x.png"]];
    [tbl_home addSubview:newView];
    [tbl_home sendSubviewToBack:newView];

}

将图像设置为背景,但存在某些单元格未显示或newView 超出某些单元格的问题。

我想像下面的截图一样设置图像:-

【问题讨论】:

  • nitin 给我一个示例代码,我会为你做的

标签: ios uitableview ios7


【解决方案1】:

经过一些更改,现在帮助使用此代码,我成功地使用此代码将图像设置为上图:-

-(void)addBackgroundViewForSectionIndex:(int)tagIndex {

    for (UIView * subview in tbl_home.subviews) {
        if(subview.tag == tagIndex)
            [subview removeFromSuperview];
    }

    CGRect sectionFrame = [tbl_home rectForSection:tagIndex];
    UIImageView *newView = [[UIImageView alloc]initWithFrame:sectionFrame];
    newView.tag = tagIndex;
    [newView setImage:[UIImage imageNamed:@"Section@2x.png"]];
    [tbl_home addSubview:newView];
    [tbl_home sendSubviewToBack:newView];

}

以前我将此方法称为cellForRowIndex,以便每次都调用并产生问题。现在我在

中调用此方法
- (void)tableView:(UITableView *)tableView willDisplayCell:(UITableViewCell *)cell forRowAtIndexPath:(NSIndexPath *)indexPath

如下所示,现在工作正常:-

- (void)tableView:(UITableView *)tableView willDisplayCell:(UITableViewCell *)cell forRowAtIndexPath:(NSIndexPath *)indexPath
{
  [self addBackgroundViewForSectionIndex:indexPath.section];
}

【讨论】:

    猜你喜欢
    • 2010-11-25
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-12-07
    • 1970-01-01
    • 1970-01-01
    • 2020-01-30
    相关资源
    最近更新 更多