【问题标题】:Change size of UITableView and put button under it更改 UITableView 的大小并将按钮放在它下面
【发布时间】:2012-06-25 17:40:07
【问题描述】:

我正在尝试缩短 UITableView 的高度并在下方放置一个按钮。我尝试使用此代码:

// set the frame size
CGRect frame = self.view.frame;
frame.size.height = 355;
self.view.frame = frame;

//set up the button
UIButton *button = [UIButton buttonWithType:UIButtonTypeRoundedRect];
[button addTarget:self 
           action:@selector(buttonPress:)
 forControlEvents:UIControlEventTouchUpInside];
[button setTitle:@"Add to Current Workout" forState:UIControlStateNormal];
button.frame = CGRectMake(20, 365, 280, 40);
[self.view addSubview:button];

在 viewDidAppear 方法中,但所发生的只是视图变短,当我向下滚动时,按钮覆盖了我的一个单元格(它也随着 tableview 滚动)。如何更改 tableview 的高度并在视图下方有一个按钮?

【问题讨论】:

    标签: iphone objective-c xcode uitableview uibutton


    【解决方案1】:

    self.view 根据文档返回“最初发生触摸的视图”。要更改 tableView,您将需要使用 self.tableView,它返回“由控制器对象管理的 tableView”,假设您在 TableViewController 中执行此操作。更改第一行和第三行:

    CGRect frame = self.tableView.frame;
    frame.size.height = 355;
    self.tableView.frame = frame;
    

    要让按钮出现在 tableView 下,按照this question,您可以将其设置为 tableView 的 tableFooterView。所以把最后一行改成:

    self.tableView.tableFooterView = button;
    

    【讨论】:

    • 我完全忽略了这一点。我进行了更改,但问题仍然存在。桌子的高度确实发生了变化,但按钮仍然不在桌子下方。它在表格的顶部,但只有在我向下滚动到它时才能看到。有什么想法吗?
    • 您是否也将最后一行从self.view 更改为self.tableView?您仍然希望将按钮添加到 self.view
    • 我刚刚找到了另一个帮助回答这个问题的 SO。相应地编辑了我的答案。
    【解决方案2】:

    您需要减小表格视图的大小,而不是整个视图的大小(就像您目前所做的那样)。

    应该是 self.tableView.frame = frame(其中 tableview 是你的 UITableView 的名称)。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2011-02-24
      • 1970-01-01
      • 1970-01-01
      • 2016-09-16
      • 2016-11-07
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多