2014-10-04 56 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