0

我可以在界面生成器中将表格视图添加到现有视图吗?

我的接口构建器如下所示

在此处输入图像描述

但是当我在模拟器中运行代码时,您可以看到该表没有显示在与界面生成器中相同的位置,因为它覆盖了底部的按钮???

在此处输入图像描述

更新...我有点进步,但底部的按钮被隐藏了??

在此处输入图像描述

已修复...按照建议使用以下代码:)

    - (UIView *)tableView:(UITableView *)tableView viewForFooterInSection:(NSInteger)section {

UIView *view = [[UIView alloc] initWithFrame:CGRectMake(0, 0, tableView.frame.size.width, 40)];

view.backgroundColor = [UIColor whiteColor];

UIButton *buttonA = [UIButton buttonWithType:UIButtonTypeRoundedRect];
buttonA.frame = CGRectMake(101,5,118,29);
[buttonA setTitle:@"Save & Exit" forState:UIControlStateNormal];
buttonA.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleLeftMargin | UIViewAutoresizingFlexibleRightMargin;

[view addSubview:buttonA];

UIButton *buttonB = [UIButton buttonWithType:UIButtonTypeRoundedRect];
buttonB.frame = CGRectMake(254,5,56,29);
[buttonB setTitle:@"Next" forState:UIControlStateNormal];
buttonB.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleLeftMargin | UIViewAutoresizingFlexibleRightMargin;

[view addSubview:buttonB];

return view;

}

    - (CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section {
return 40;

}

4

3 回答 3

0

确保已将 tableview 的委托和数据源附加到文件所有者。您还必须至少实现这两种方法。

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section;

// Row display. Implementers should *always* try to reuse cells by setting each cell's reuseIdentifier and querying for available reusable cells with dequeueReusableCellWithIdentifier:
// Cell gets various attributes set automatically based on table (separators) and data source (accessory views, editing controls)

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath;

例如,检查此链接!

于 2013-02-27T09:33:11.650 回答
0

将自动调整大小应用于 .xib 文件中的这些子视图,如下所示......

在此处输入图像描述

或者

您可以使用以下功能以编程方式更改..

UIViewAutoresizing
Specifies how a view is automatically resized.

enum {
   UIViewAutoresizingNone                 = 0,
   UIViewAutoresizingFlexibleLeftMargin   = 1 << 0,
   UIViewAutoresizingFlexibleWidth        = 1 << 1,
   UIViewAutoresizingFlexibleRightMargin  = 1 << 2,
   UIViewAutoresizingFlexibleTopMargin    = 1 << 3,
   UIViewAutoresizingFlexibleHeight       = 1 << 4,
   UIViewAutoresizingFlexibleBottomMargin = 1 << 5
}; 

例子是:

  [yourViews.autoresizingMask = UIViewAutoresizingFlexibleHeight | UIViewAutoResizingFlexibleWidth];
于 2013-02-27T09:39:49.680 回答
0
- (UIView *)tableView:(UITableView *)tableView viewForFooterInSection:(NSInteger)section

在数据源方法中返回页脚视图(包含“保存和编辑”和“下一步”UIButtons 的 UIView)。

于 2013-02-27T09:41:05.737 回答