Tableview导致崩溃

时间:2014-10-14 22:49:53

标签: ios objective-c uitableview

我正在尝试使用光滑的滚动实现表(不是节标题)的自定义标题视图,我正在使滚动工作,但是当我解开segue时它会崩溃我的应用程序。标题视图是否未被释放或是什么?异常断点没有帮助。

以下是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;
}

以下是自定义标题视图的代码:

@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

0 个答案:

没有答案