2016-08-23 12 views
0

セルまたはボタンをクリックした場所を実装しました。tableviewcellが展開されます。しかし、問題は、私が最後にcellを展開すると、それがtableviewの後ろにあることです。 tableviewのサイズを変更してセルを少し上に移動するにはどうしたらいいですか?セルを展開するとテーブルビューが大きくならない

私は制約とviewsセル内で単純に作った。

このように、青色がメインで、ブラックが展開する予定です。私はコードそれを知らない

enter image description here

はnecessrayですが、これは、私はそれを拡大するにする方法です。

これはcellForRowAtIndexPath内にある:

if (self.selectedIndex == indexPath.row){ 
       self.selectedIndex = -1 
      }else{ 
       self.selectedIndex = indexPath.row 
      } 

      self.productstable.beginUpdates() 
      self.productstable.reloadRowsAtIndexPaths([indexPath], withRowAnimation: UITableViewRowAnimation.Automatic) 
      self.productstable.endUpdates() 
     } 
     return cell 

これはheightForRowAtIndexPath内にある:

if(selectedIndex == indexPath.row){ 
    return 210 
}else{ 
    return 135 
} 

私は最後cellを検出し、それを上に移動しようとしたが、それが動作していません。

答えて

1

チェックこのコード

func reloadChange() 
{ 
    let indexPath = NSIndexPath(forRow: selectedIndex, inSection: 0) 
    self.tableView.reloadRowsAtIndexPaths([indexPath], withRowAnimation: UITableViewRowAnimation.None) 
    //this is the way to scroll to your last cell 
    self.tableView.scrollToRowAtIndexPath(indexPath, atScrollPosition: .Bottom, animated: true) 
} 


func tableView(tableView: UITableView, didSelectRowAtIndexPath indexPath: NSIndexPath) { 
    //code to expand and shrink your cell 
    if(self.selectedIndex == indexPath.row) 
     { 
     self.selectedIndex = -1 
     self.tableView.reloadRowsAtIndexPaths([indexPath], withRowAnimation: UITableViewRowAnimation.None) 
    //this is the way to scroll to your last cell 
    self.tableView.scrollToRowAtIndexPath(indexPath, atScrollPosition: .Bottom, animated: true) 
     return 
     } 
    self.selectedIndex = indexPath.row 
    self.reloadChange() 
} 

は、私は、これはあなたがそれは最後のものだけではありません `cells`のために働いている

+0

に役立ちます願っています。 –

+0

cellForRowAtIndexPathのコードを削除しましたか? –

+0

Ohh。それは実際には動作していますが、2度目のクリックではもう閉じません。だから、私が望んだことをやっているが、何かを壊した:D –

関連する問題