0

I'm trying to implement a custom header view for a table (not section header) with a slick scroll and I'm getting the scroll to work, but it's crashing my app when I unwind the segue. Is the header view not being released or something? An exception breakpoint isn't helping.

Here's the code for the tableview:

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    self.tableView.delegate = self;
    self.tableView.dataSource = self;

    self.headView = [HappyHourHeaderView headerInit];

    self.headView.height = 200.0f;
    self.headView.headerImage.height = 200.0f;
    self.headView.headerImage.y = 0.0f;
    self.headView.headerImage.contentMode = UIViewContentModeScaleAspectFill;

    self.tableView.tableHeaderView = self.headView;
}

Here's the code for the custom header view:

@implementation HappyHourHeaderView

+(instancetype)headerInit
{
    HappyHourHeaderView *tableHeader = nil;
    NSArray *objects = [[NSBundle mainBundle] loadNibNamed:@"HappyHourHeaderView" owner:nil options:nil];

    tableHeader = objects[0];
    tableHeader.headerImage.image = [UIImage imageNamed:@"theImage"];
    tableHeader.headerImage.frame = CGRectMake(0, 0, tableHeader.width, tableHeader.height);
    tableHeader.clipsToBounds = YES;

    return tableHeader;
}

-(void)tableDidScrollWithY:(float)y{

    float constant = y + 64;

    if (constant >= 0) {
        self.clipsToBounds = YES;
        self.headerImage.y = MAX(0,  constant - (constant * 0.4));
        self.headerImage.height = 200;
    }
    else{
        self.clipsToBounds = NO;
        self.headerImage.y =  MIN(0,  constant);
        self.headerImage.y = 0;
        self.headerImage.height = 200 - constant;
    }
    self.height = 200;
    self.y = 0;
    self.headerImage.clipsToBounds = YES;
}

@end
kerbelda
  • 325
  • 1
  • 4
  • 14
  • 1
    Post details about the crash including the complete error message and point out which line of code is crashing. – rmaddy Oct 14 '14 at 22:55
  • What's going on with this line: self.headView.height = 200.0f; Actually, you have a lot of lines where you are setting size variables directly on views. What class are you basing your header view off of? – Acey Oct 14 '14 at 23:59
  • Learn how to collect the exception info. This may help: http://stackoverflow.com/q/8100054/581994 – Hot Licks Oct 15 '14 at 00:42
  • [This is all I get](http://i.imgur.com/09IlooB.png). Hot Licks I tried using the ARC bit from that thread but it makes the app launch with a black screen. It only crashes if I scroll to the bottom of the table and THEN hit the back button. Acey, the second bit of code I posted is the custom header view class. – kerbelda Oct 15 '14 at 01:06

0 Answers0