headerView does not show on the window


#1

I am a novice learning IOS programming.
I think I typed in as the book described for the headerVIew in ItemsViewController.h and ItemsViewController.m.
Also, I created HeaderView.xib and changed the File’s owner to the custom class ItemsViewController with the Outlets connection headerView to View.
When I build and run, the UITableView shows with rows populated from the RandomPossession data. There is no top headerView with ‘Edit’ and ‘New’ button.

Could you please give me a hint where I did wrong?
Thank you.


#2

I’m assuming you also implemented the methods shown on pages 194 and 195. If so, maybe you have a typo in one of those?

Doug


#3

Thank you for the reply.

On the page 195 at bottom, it says the 2 methods are optional, so I omitted.
It turned out that they are not optional. They are required to have the header with 2 buttons show up at the top.

Thank you.


#4

Also in fig 11.5, the headerView connection between File’s Owner and the View isn’t in bold like the other connections are. I missed that, then couldn’t work out why I wasn’t seeing anything!


#5

Bold connections mean actions and non-bold mean instance variables. I think we made a few mistakes over the course of the book on this one.

However, all connections shown must always be connected, bold or not.


#6

I had a similar issue and noticed I had selected the wrong method because I got careless with the autocomplete:

In ItemsViewController.m, I had this method:

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath

instead of this method:

- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section

Could that be causing your issue. Note that it won’t raise any errors, you just might get the UIView with the buttons floating over the top of the UITableView.

Hope this helps!

Regards,


#7

I think there the code at page 194 is incorrect. This is how I’ve done it.

- (UIView*)headerView
{
    // If we haven't loaded the headerView yet...
    if (!headerView) {
        // Load HeaderView.xib
        headerView = [[[NSBundle mainBundle] loadNibNamed:@"HeaderView" owner:self options:nil] lastObject];
    }
    return headerView;
}

#8

[quote=“jkmin1”]Thank you for the reply.

On the page 195 at bottom, it says the 2 methods are optional, so I omitted.
It turned out that they are not optional. They are required to have the header with 2 buttons show up at the top.

Thank you.[/quote]

I guess you misunderstood what the author meant with “These two methods are optional, but if you implement one, you must implement both”. I understand it like: if you use one of the methods you have to use the other one, too! And of course you need them to show the Header in the HeaderSection for TableViews.

[quote=“To1ne555”]I think there the code at page 194 is incorrect. This is how I’ve done it.
[/quote]

The code at page 194 worked for me. I didn’t have any problems in that chapter. Maybe you have Typomistake or something like this.


#9

Thanks To1ne555 for figuring it out. I had the same problem and your fix worked for me too. Maybe this is an iOS version difference issue?