我可以在界面构建器中的现有视图中添加tableview。
我的界面构建器如下所示
但是当我在模拟器中运行代码时,您可以看到该表未显示在界面构建器中的相同位置,因为它覆盖了底部的按钮???
UPDATE ... 我有点进步,但底部的按钮是隐藏的?
FIXED ... ,建议使用以下代码:)
- (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;
}
答案 0 :(得分: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;
答案 1 :(得分: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];
答案 2 :(得分:0)
- (UIView *)tableView:(UITableView *)tableView viewForFooterInSection:(NSInteger)section
数据源方法中的返回页脚视图(包含“save&amp; edit”和“next”UIButtons的UIView)。