简体   繁体   中英

How do I pull a UIView out of a UITableView created via storyboard?

So I'm more or less trying to do this:

How to embed a UITableView in a UIScrollview

however, I can't seem to figure out how to obtain a 'subview' (I use quotes as I'm not sure it's officially a subview per the API however it lives within another view of a VC) so that I can then set it as the UITableView's header. Additionally, going through all the options available in the storyboard I don't see how to set it as the UITableView's header there either. I would greatly appreciate any help!

Relevant storyboard shots, here is the hierarchy:

我将视图拖到TableViewController中,如果您愿意,这是层次结构

And here's what the UITableViewController itself looks like. I'm trying to set the grey block as the header so that it doesn't scroll:

在此处输入图片说明

Programmatically this is what I'm looking to accomplish (assuming I'm on the right track!):

UIView *viewForHeader = [[self tableView] SOMEWAYTOGETTHEINNERVIEW?];
[[self tableView] setTableHeaderView:viewForHeader]

and if I can somehow set the view as the header in XCode 5 with iOS 7 that would be great as well! It seems in older versions for this situation the view would default as the header:

Table Header Views in StoryBoards

You can create a custom class that inherits from UITableView and set your table view to be that class. Then you can create an outlet from that view to your custom class. Like so:

CustomTableView.h

@interface CustomTableView : UITableView
@property (weak, nonatomic) IBOutlet UIView *viewForHeader;
@end

And then the code you were trying to do:

UIView *viewForHeader = [self tableView].viewForHeader;
[[self tableView] setTableHeaderView:viewForHeader]

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM