【问题标题】:How to insert UIImageView between two sections of UITableView?如何在 UITableView 的两个部分之间插入 UIImageView?
【发布时间】:2011-02-09 06:00:30
【问题描述】:

我在我的应用程序中进行了设计,就像我的 UITableView 中有 4 个部分一样,我需要在同一个表的部分之间插入 UIImageView 和 UILabel。是否可以这样做?

请给我指路。谢谢。

【问题讨论】:

    标签: iphone objective-c ios uitableview uiimageview


    【解决方案1】:

    查看这些 UITableViewDelegate 方法:

    -(UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger) section
    -(UIView *)tableView:(UITableView *)tableView viewForFooterInSection:(NSInteger) section
    

    您可能需要将图像视图和标签包含在 IUView 容器中,并从这些方法之一返回容器。这取决于您想要呈现的内容和方式。

    【讨论】:

      【解决方案2】:

      你的餐桌风格是UITableViewStyleGrouped吗?

      如果是这样,请使用UITableViewDelegateviewForHeaderInSection:viewForFooterInSection: 方法。创建一个视图,将图像和标签添加到视图中,然后从上述两个委托方法中的任何一个返回到视图。我想,您正在使用图像和标签作为该部分的标题。所以,tableView:viewForHeaderInSection: 就是您所需要的。

      【讨论】:

        【解决方案3】:

        我以这种方式实现,它根据我的需要显示图像。感谢您显示路径,我正在显示代码以防其他人需要。谢谢。

           -(UIView *)tableView:(UITableView *)tableView viewForFooterInSection:(NSInteger) section
            {
                    UIView *header = [[UIView alloc] initWithFrame:CGRectMake(0,5,320,40)];
                    UIImageView *imgAdbar = [[UIImageView alloc]initWithFrame:CGRectMake(header.frame.origin.x,header.frame.origin.y,header.frame.size.width,header.frame.size.height)];
                    [imgAdbar setImage:[UIImage imageNamed:@"ad2.png"]];
                    [header addSubview:imgAdbar];
                    header.backgroundColor = [UIColor clearColor];
                    return header;
            }
        

        【讨论】:

          【解决方案4】:

          我认为您需要创建一个自定义视图,其中包含四个单独的表,每个表有一个部分,并将图像视图和 uilabel 放在每个表之间。

          【讨论】:

            猜你喜欢
            • 2015-01-12
            • 1970-01-01
            • 1970-01-01
            • 1970-01-01
            • 1970-01-01
            • 1970-01-01
            • 1970-01-01
            • 2018-08-24
            • 1970-01-01
            相关资源
            最近更新 更多