0

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:

I dragged the view over into the TableViewController, here is the hierarchy if you will

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:

enter image description here

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

Community
  • 1
  • 1
the1337sauce
  • 539
  • 4
  • 11
  • have you tried UIView *viewForHeader = [self tableView].tableHeaderView; ? – Connor Pearson Jan 04 '14 at 05:30
  • Yea, I've done a bunch of testing around that front... viewForHeader would then be nil as the tableView for sure right now has no tableHeaderView set – the1337sauce Jan 04 '14 at 05:36
  • My bad I thought you were trying to get the header. – Connor Pearson Jan 04 '14 at 05:43
  • You need to add the tableview to the view but in smaller scale. Just create a view and then add a tableview to it ( on the bottom) the use whatever you want on top and set the delegate and data source of the table and connect them. – Adrian P Jan 04 '14 at 05:44

1 Answers1

1

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]
Connor Pearson
  • 63,902
  • 28
  • 145
  • 142
  • this didn't work for some reason, I really thought it was going to it makes sense. I created a custom UITableView called SplitDetailTV and created an outlet from what I want to be the headerView UIView to it that looks just like above. Then programmatically set it like in your second code blurb above. I can now verify that the headerView is not nil so something is being set but it's still scrollable. Is it possible the header now scrolls and the design style from the top stack overflow link above is no longer possible? – the1337sauce Jan 04 '14 at 16:40
  • so you want the header to stay in the same place while you scroll? – Connor Pearson Jan 04 '14 at 16:50
  • yeah exactly, I want to be able to scroll through the cells while the header bit staying in place. like a split view sort of thing, originally I had thought I needed a UIView with an embedded UITableView on the bottom but had read this was possible and it seems simpler – the1337sauce Jan 04 '14 at 16:51
  • http://stackoverflow.com/a/6961973/754604 this looks like it's the same problem you have now – Connor Pearson Jan 04 '14 at 16:54
  • yep i'm going that route now. Thanks a lot for your help! – the1337sauce Jan 04 '14 at 20:09