Jon*_*Jon 2 iphone cocoa-touch objective-c uitableview uiview
我的VC是子类,UITableViewController我试图UIButton在屏幕底部添加一个.
当我的VC中UIView有一个UITableView对象时,我知道如何做到这一点,但是当我进行子类化时如何添加此按钮UITableView?我尝试在IB中添加它,但它只允许我将其添加为表格的页脚,只有当表格的底部滚动到时才会显示.有任何想法吗?
而且,如何在保持细胞白色的同时在桌子后面添加图像?课堂上很容易UIView,但在这种情况下不确定.
建议1:您可以创建一个单独的视图,其中包含您的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
Run Code Online (Sandbox Code Playgroud)
Suggestion2:您可以使用viewForFooterInSection委托方法.您可以在其中创建视图并添加UILabel.viewForFooterInSection返回UIView,您可以返回包含UILabel的视图
备注:滚动tableView时,默认页脚将与tableView一起移动
注意 :
如果您的视图是UITableViewController的子类,那么可以将其更改为UIViewController并在您的nib文件中创建一个视图并在视图下拖动您的tableView并将引用类更改为您的UIViewController.现在创建一个UITableView*myTableView的IBOutlet并将其连接到您的nib文件.你只需要将你的VC文件中的self更改为[self.myTableView reloadData];
很好的代码
UIView *headerView = [[[UIView alloc] initWithFrame:CGRectMake(0, 0, 300, 80)] autorelease];
UIButton *btn = [UIButton buttonWithType:UIButtonTypeRoundedRect];
btn.frame = CGRectMake(10,10, 300, 40);
[btn setTitle:@"showProfile" forState:UIControlStateNormal];
[btn addTarget:self action:@selector(your_function) forControlEvents:UIControlEventTouchUpInside];
[headerView addSubview:btn];
tbl.tableFooterView = headerView;
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
11310 次 |
| 最近记录: |