2017-06-15 88 views
1

我創建了一個UIViewController,它包含兩個View(頂部,底部), 底部視圖在單擊searchBar時一直展開到頂部。 (bottomView高度擴大,topView高度越來越小)。didSelectRowAt indexPath沒有被調用

func searchBarShouldBeginEditing(_ searchBar: UISearchBar) -> Bool { 
    self.expandBottomView() 
    return true 
} 

func expandBottomView() { 
    let heightToAdd = TopView.frame.height - numOfRequestsTitle.frame.height 

    RecomandFriendHeight.constant += heightToAdd 
    UIView.animate(withDuration: 0.5) { 
     self.view.layoutIfNeeded() 
    } 

    topTableView.isUserInteractionEnabled = false 
} 

這兩個視圖都包含TableViews(topTableView,BottomTableView)所有代表都被設置了我檢查。 BottomView包含另一個按鈕以在需要時摺疊bottomView。

topTableViewCell包含兩個按鈕和兩個標籤。 bottomTableViewCell包含一個標籤和一個imageView。

問題是沒有一個tableViews單元調用didSelectRowAt。 enter image description here

+0

要被代表設置什麼課? – CoderFrom94

+0

到包含topView和bottomView的UIViewController。 –

+0

你能提供更多的代碼嗎?我希望看到爲tableViews和didSelectRowAt方法聲明都設置了委託和數據源。 – CoderFrom94

回答

0

如果將按鈕添加到單元格didSelectAt未點擊按鈕調用。在這種情況下,你必須選擇添加到該按鈕內cellForRowAt:

func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell { 
     let cell = tableView.dequeueReusableCell(withIdentifier: "cell", for: indexPath) as! customcell 
     cell.btn.addTarget(self, action: #selector(clickedCell), for: .touchUpInside) 
     return cell 

    } 

,並實現該選擇方法

func clickedCell(_ sender : UIButton) { 
     print("clicked") 
} 
0


topTableView.isUserInteractionEnabled = true