如何添加UIButton在UITableVIew下? [英] How To Add UIButton Below UITableVIew?

查看:97
本文介绍了如何添加UIButton在UITableVIew下?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的VC是UITableView的子类,我试图在屏幕的按钮添加一个UIButton。

My VC is a subclass of UITableView and I'm trying to add a UIButton at the button of the screen.

我知道如何做到这一点,当我的VC是一个UIView与UITableView对象,但是当我是子类化UITableView时,如何添加此按钮?我试图在IB中添加它,但它只允许我添加它作为表的页脚,这只有在表的底部滚动到时才可见。任何想法?

I know how to do this when my VC is a UIView with a UITableView object in it, but how can I add this button when I'm subclassing UITableView? I tried adding it in IB but it only lets me add it as the table's footer, which is only visible when the bottom of the table is scrolled to. Any ideas?

还有,如何在桌子后添加一个图像,同时保持细胞白色?

And also, how can I add an image behind the table while keeping the cells white? Its easy when the class is uiview, but not sure in this case.

推荐答案

建议1:您可以创建一个单独的视图包含您的UIButton和下面的UITableView。

Suggestion1 : You could have create a separate view which contains your UIButton and place below of the UITableView.

注意:这是非常有用的,因为当您滚动tableView时,默认页脚将停留在底部。

Remark : This is useful because when you scroll the tableView the default footer will be stick to bottom.

// 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委托方法。您可以在其中创建视图并添加UILabel。 viewForFooterInSection返回UIView,可以返回包含UILabel的视图

Suggestion2 : you can use viewForFooterInSection delegate method. where you can create a view and add the UILabel. viewForFooterInSection returns the UIView, which you can return your view which contains the UILabel

注意:当滚动tableView时,默认页脚将随tableView移动

Remark : when you scroll the tableView the default footer will move along with your tableView

注意:


如果您的视图是UITableViewController的子类,可以将其更改为UIViewController并在您的nib文件中创建一个视图并在视图下拖动您的tableView并将引用类更改为您的UIViewController。现在创建一个UITableView * myTableView的IBOutlet并将其连接到您的nib文件。你只需要在你的VC文件中改变例如self到[self.myTableView reloadData];

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];

这篇关于如何添加UIButton在UITableVIew下?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆