0

I need table view with custom header view. When i touch this header view i'll make her resize. I have class topBarViewController with next code (for example):

topBarViewController class:

- (void)viewDidLoad
{
    [super viewDidLoad];

    self.view.frame = CGRectMake(0, 0, 320, 48);

    [self.view setBackgroundColor:[UIColor greenColor]];

    UITapGestureRecognizer *singleFingerTap =
    [[UITapGestureRecognizer alloc] initWithTarget:self
                                            action:@selector(handleSingleTap:)];
    [self.view addGestureRecognizer:singleFingerTap];
}

- (void)handleSingleTap:(UITapGestureRecognizer *)recognizer
{
    [UIView animateWithDuration:0.5 animations:^{
        CGRect frame = self.view.frame;
        frame.size.height+=50;
        self.view.frame = frame;
    } completion:^(BOOL finished) {

    }];
}

Then i set this view as header view for my table view. On touch event i've got crash with next text:

    2014-10-05 01:00:07.580 UGTUMap[4715:1988098] -[UITransitionView handleSingleTap:]:
 unrecognized selector sent to instance 0x7ff6d542a5f0

    2014-10-05 01:00:07.586 UGTUMap[4715:1988098] *** Terminating app due to uncaught 
exception 'NSInvalidArgumentException', reason: '-[UITransitionView handleSingleTap:]:
 unrecognized selector sent to instance 0x7ff6d542a5f0'

Can't find solution. Any suggestions?

Oleg Sobolev
  • 3,286
  • 2
  • 16
  • 29
  • 1
    Show the code where you create your `topBarViewController` and set it up as the table view's header view. My guess is that you create the `topBarViewController`, use its view, but never keep a strong reference to the view controller (`topBarViewController` instance). – rmaddy Oct 04 '14 at 21:38
  • @rmaddy thank you, strong reference is a solution! – Oleg Sobolev Oct 04 '14 at 21:57

1 Answers1

0

You don't want top animate the size of the headerView directly. You want to tell the UITableView to change the size through the UITableViewDelegate protocol.

So I assume that you are doing something like this to set up your header:

- (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section {
    return self.topBarViewController.view;
}

In your UITableViewDelegate set up a property to hold your headerView height;

@property (nonatomic, assign) CGFloat headerViewHeight;

The implement the heightForHeaderInSection to return this variable.

- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section {
    return self.headerViewHeight;
}

When you detect a tap on the headerView, you can tell the tableView to animate updates:

- (void)headerWasTapped {

    // set new height
    self.headerViewHeight = 100.0f

    // animate updates
    [self.tableView beginUpdates];
    [self.tableView endUpdates];
}
dfmuir
  • 2,048
  • 1
  • 17
  • 14
  • While much of this is true, it make no attempt to answer the question - which is about a crash. – rmaddy Oct 04 '14 at 21:42