我有一个Storyboard,其中包含 UITableViewController 。表视图是静态的,包含两个部分。表视图完全在IB中设置(包括表视图部分的页眉和页脚文本) - 我没有在视图控制器中实现任何表视图委托方法。
I have a Storyboard which contains a UITableViewController. The table view is static and contains two sections. The table view was setup entirely in IB (including the header and footer text of the table view sections) - I have not implemented any table view delegate methods in my view controller.
如果我尝试获取对给定部分的 UITableViewHeaderFooterView 的引用,它总是返回nil。
If I attempt to get a reference to the UITableViewHeaderFooterView for a given section it always returns nil.
UITableViewHeaderFooterView* header =[self.tableView headerViewForSection:0];当我运行应用程序时,我可以看到我在IB中设置的页眉和页脚文本,所以我知道那些观点在那里。我只是无法弄清楚如何以编程方式访问它们。
When I run the app I can see the header and footer text that I set in IB so I know those views are there. I just can't figure out how to access them programmatically.
任何帮助都将非常感激, CS
Any help would be much appreciated, CS
推荐答案实际上,您需要指定表格页脚视图,并使用其委托将其传递给表格视图。
Actually you'll need to specify the table footer view, and pass it to the table view using its delegate.
例如,假设您已经定义了一个名为tableFooterView的IBOutlet UIView。 然后在下面的委托方法中,您可以将tableFooterView传递给表视图:
For example, suppose you have defined a IBOutlet UIView named tableFooterView. Then in the following delegate method, you can pass your tableFooterView to your table view:
- (UIView *)tableView:(UITableView *)tableView viewForFooterInSection:(NSInteger)section; // custom view for footer. will be adjusted to default or specified footer height { return self.tableFooterView; }此外,您还需要实现以下方法来设置高度表页脚视图:
Also you'll need to implement the following method to set the height of the table footer view:
-(CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section { return self.tableFooterView.frame.size.height; }更多推荐
获取静态UITableView的UITableViewHeaderFooterView
发布评论