2014-10-04 53 views
0

我需要具有自定义标题视图的表格视图。当我触摸这个标题视图时,我会让她调整大小。我有下一个代码(例如)类topBarViewController智能UITableView标题视图

topBarViewController类:

- (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) { 

    }]; 
} 

然后我设置此视图作为我的表视图头视图。在触摸事件我碰到了下一个文字:

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' 

找不到解决方案。有什么建议么?

+1

显示在您创建'topBarViewController',并将它设置为表视图的标题代码视图。我的猜测是,你创建'topBarViewController',使用它的视图,但从来没有保持强大的引用视图控制器('topBarViewController'实例)。 – rmaddy 2014-10-04 21:38:29

+0

@rmaddy谢谢你,强烈的参考是一个解决方案! – 2014-10-04 21:57:04

回答

0

你不想让top直接为headerView设置动画大小。你想通过UITableViewDelegate协议告诉UITableView改变大小。

所以我假设你正在做这样的事情来设置你的头:

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

在你的UITableViewDelegate建立一个属性来保存你的headerView高度;

@property (nonatomic, assign) CGFloat headerViewHeight; 

执行heightForHeaderInSection返回这个变量。

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

当你发现在headerView一个水龙头,你可以告诉的tableView动画更新:

- (void)headerWasTapped { 

    // set new height 
    self.headerViewHeight = 100.0f 

    // animate updates 
    [self.tableView beginUpdates]; 
    [self.tableView endUpdates]; 
} 
+0

虽然大部分情况都是如此,但它并没有试图回答这个问题 - 这是关于崩溃的问题。 – rmaddy 2014-10-04 21:42:39