【问题标题】:Button placement on table footer view表格页脚视图上的按钮位置
【发布时间】:2010-11-23 00:19:52
【问题描述】:

我有一个表格视图,其中单元格的数字不是固定的,并且会不断变化。我必须在表格页脚的最后一个单元格之后显示两个操作按钮。在我的最后一个单元格之后如何正确放置它们?我知道最后一个单元格和这些按钮之间的像素间距。任何代码示例都会很有帮助。

【问题讨论】:

  • UITableView 是 Cocoa Touch 的一部分,而不是 Cocoa。
  • 我的错。谢谢指正!

标签: iphone cocoa-touch uitableview uikit


【解决方案1】:

您是否尝试过将它们粘贴在视图中并将其设置为页脚视图?

你需要在添加之前给它正确的高度;宽度自动设置为表格的宽度。将其设置为合理的宽度(例如 320)并使用自动调整大小或使用自定义 UIView 子类并实现 -layoutSubviews。

【讨论】:

    【解决方案2】:

    您总是可以在最后一个单元格中添加两个按钮。

    - (NSInteger)tableView:(UITableView *)aTableView numberOfRowsInSection:(NSInteger)section {
      return [myCellDataArray count]+1;
    }
    
    - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
      UITableViewCell *cell = nil;
      if (indexPath.row > [myCellDataArray count]) {
        cell = [tableView dequeueReusableCellWithIdentifier:@"Button Cell"];
        if (cell == nil) {
          UIButton *firstButton = [[UIButton alloc] init];
          //customization
          UIButton *secondButton = [[UIButton alloc] init];
          //customization
    
          [cell addSubView:firstButton];
          [cell addSubView:firstButton];
        }
    } else {
      // normal stuff
    }
    

    如果您想自定义现有按钮,您需要将其标签设置为独特的,即firstButton.tag = 100,然后通过firstButton = (UIButton *)[cell viewWithTag:100]; 设置 firstButton。确保定义 firstButton 使其在范围内!

    希望这会有所帮助!

    【讨论】:

    • 好的。知道了。但是这样做的标准方法是什么。在这种情况下,假设我只有两个单元格,在第三个单元格中放置这些按钮,然后屏幕的其余部分将是空白的。这是正确的做法吗?
    • 如果您查看一些标准的 Apple 应用程序,它们有时会在列表下方有两个或更多按钮,当该列表很短时,它仍然停留在列表下方。我想它可能会增加规律性,而且编码也更容易:P。只是出于兴趣,这两个按钮是什么?
    • 它是一个与购物车相关的应用程序。我有一个按钮是“添加到购物车”,另一个是“删除”。
    猜你喜欢
    • 2010-12-24
    • 1970-01-01
    • 1970-01-01
    • 2020-01-09
    • 1970-01-01
    • 2011-01-27
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多