向表格视图添加多个水平按钮

时间:2012-08-08 22:45:42

标签: ios uitableview

我尝试了很多东西 - 从对象浏览器添加一个按钮,更改属性,搜索网络,但没有运气。基本上,我想做 - 在故事板 - 中:pin screenshoot

你看到"添加到联系人" "分享位置"和"添加到书签"。

3 个答案:

答案 0 :(得分:4)

您应该创建一个UITableViewCellcontentView拥有3个单独的UIButtons。 要以编程方式执行此操作,请在tableView:cellForRowAtIndexPath:数据源方法中使用类似于以下内容的代码:

- (UITableViewCell*) tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    static NSString* identifier = @"cell";
    UITableViewCell* cell = [tableView dequeueReusableCellWithIdentifier:identifier];
    if (!cell) {
        cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:nil];
        cell.backgroundColor = [UIColor clearColor];
        UIButton* button1 = [UIButton buttonWithType:UIButtonTypeRoundedRect];
        UIButton* button2 = [UIButton buttonWithType:UIButtonTypeRoundedRect];
        UIButton* button3 = [UIButton buttonWithType:UIButtonTypeRoundedRect];
        button1.frame = UIEdgeInsetsInsetRect(cell.contentView.bounds, UIEdgeInsetsMake(0, 0, 0, 250)); 
        button2.frame = UIEdgeInsetsInsetRect(cell.contentView.bounds, UIEdgeInsetsMake(0, 125, 0, 125)); 
        button3.frame = UIEdgeInsetsInsetRect(cell.contentView.bounds, UIEdgeInsetsMake(0, 250, 0, 0)); 
        button1.autoresizingMask = UIViewAutoresizingFlexibleRightMargin;
        button2.autoresizingMask = UIViewAutoresizingFlexibleRightMargin | UIViewAutoresizingFlexibleLeftMargin;
        button3.autoresizingMask = UIViewAutoresizingFlexibleLeftMargin;
        [cell.contentView addSubview:button1];
        [cell.contentView addSubview:button2];
        [cell.contentView addSubview:button3];
    }

    return cell;
}

此外,在您的委托的tableView:willDisplayCell:方法中,执行以下操作以使单元格的默认装饰完全消失:

- (void) tableView:(UITableView *)tableView willDisplayCell:(UITableViewCell *)cell forRowAtIndexPath:(NSIndexPath *)indexPath
{
    cell.backgroundView = nil;
}

您应该获得与您发布的结果非常相似的结果。

答案 1 :(得分:2)

将三个按钮放在宽度为320像素,高度为60的UIView中,并将该视图设为桌面的页脚。

答案 2 :(得分:2)

UITableView使用UITableViewStyleGrouped标准进行样式设置 这三个UIButtons以编程方式添加到tableView.tableFooterView 或者,您可以向最后UIButtons的{​​{1}}添加三个contentView

添加以下按钮:

cell

使用反复试验正确获取按钮位置:)

相关问题