iphone - 如何在UITableView下面添加UIButton?

标签 iphone objective-c cocoa-touch uitableview uiview

我的 VC 是 UITableViewController 的子类,我正在尝试在屏幕底部添加一个 UIButton

当我的 VC 是一个带有 UITableView 对象的 UIView 时,我知道如何执行此操作,但是当我子类化 时如何添加此按钮>UITableView?我尝试将其添加到 IB 中,但它只允许我将其添加为表格的页脚,只有当滚动到表格底部时才可见。有什么想法吗?

此外,如何在表格后面添加图像,同时保持单元格为白色?当类是 UIView 时很容易,但在这种情况下不确定。

最佳答案

建议1:您可以创建一个单独的 View ,其中包含您的 UIButton 并放置在 UITableView 的下方。

备注:这很有用,因为当您滚动 tableView 时,默认页脚将粘在底部。

// position(change according to your position) of the bottom view 
                                             //and set the size of the button

UIView* bottomView = [[UIView alloc] initWithFrame:CGRectMake(5.0, 460.0, 300.0, 80.0)];
UIButton *myButton = [UIButton buttonWithType:UIButtonTypeRoundedRect];

// position(change according to your position) of the button inside bottomView
                                             //and set the size of the button
myButton.frame = CGRectMake(20, 20, 200, 44);

[myButton setTitle:@"Click Me!" forState:UIControlStateNormal];
// add targets and actions
[myButton addTarget:self action:@selector(buttonClicked:) forControlEvents:UIControlEventTouchUpInside];
// add to a view
[bottomView addSubview:myButton]; // add the button to bottom view
[self.view addSubView:bottomView]; //add bottom view main view

建议2:您可以使用viewForFooterInSection委托(delegate)方法。您可以在其中创建 View 并添加 UILabel。 viewForFooterInSection 返回 UIView,您可以返回包含 UILabel 的 View

备注:当您滚动 tableView 时,默认页脚将随着 tableView 一起移动

注意:

If your view is the subclass of UITableViewController, okay then change it to UIViewController and in your nib file Create a view and drag your tableView under the view and change the reference class to your UIViewController. Now create an IBOutlet of UITableView* myTableView and connect it to you nib file. you just need to change in your VC file for example self to [self.myTableView reloadData];

关于iphone - 如何在UITableView下面添加UIButton?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6933394/

相关文章:

iphone - 使用 safari 或 map 打开 map

ios - 我正在使用 alamofire 5 beta 版本进行 api 调用。在传递正确的参数后,我得到无效的响应参数

ios - 在运行时更改自动布局

objective-c - 如何在我的倒计时 ios 应用程序中使用用户的输入?

xcode - 将 SQLite3 数据库逆向工程到 coredata

iphone - 使用 BSD 许可证库,它使用 GPL 库,用于 iPhone

iphone - 支持视网膜和非视网膜显示屏的图形

ios - 单击它时更改 UITableViewCell 中按钮的图像。

iphone - 按下时 UILongPressGestureRecognizer 被调用两次

iphone - 导航到 SplitViewController