2016-05-29 10 views

Odpowiedz

5

Chociaż nie można zatrzymać tabeli statycznego od stara się pokazać swoje komórki, można ustawić ich wysokość do zera, dzięki czemu skutecznie niewidoczny:

Dodaj tę metodę do tabeli klasy widok kontroler Delegat:

func tableView(tableView: UITableView, heightForRowAtIndexPath indexPath: NSIndexPath) -> CGFloat { 
    let cell = super.tableView(tableView, cellForRowAtIndexPath: indexPath) 
    return cell == myHiddenCell ? 0 : super.tableView(tableView, heightForRowAtIndexPath:indexPath) 
} 
0

W metodzie didSelectCellAtIndexPath można ustawić wysokość na 0, aby go ukryć:

func tableView(tableView: UITableView, didSelectRowAtIndexPath indexPath: NSIndexPath) { 
    if indexPath.row == 0 { 
     let indexPath = NSIndexPath(forItem: 1, inSection : 0) 
     let secondCell = tableview.cellForRowAtIndexPath(indexPath) 
     secondCell.frame.size.height = 0; 
     self.view.layoutSubviews() 
    } 
} 

Jeśli chcesz animację, wystarczy umieścić self.view.layoutSubviews() w metodzie animacji UIView UIView.animateWithDuration ... itd.

0

Dla mnie ustawienie wysokości na 0 dla niektórych komórek i innej wysokości dla innych komórek nie było opcją, ponieważ wszystkie moje komórki mają różną wysokość.

Stworzyłem inną komórkę w Storyboard i ustawiłem wysokość wiersza 0 (w inspektorze rozmiaru). Następnie w kodzie pokazuję komórkę z wysokością = 0, jeśli chcę ją ukryć, jeśli nie, pokazuję drugą komórkę:

if (hideCell) { 
      let hiddenCell = tableView.dequeueReusableCell(withIdentifier: "hiddenCell",for: indexPath) as! TheWallTableViewCell 
      return hiddenCell 
     } 
else { 
     let cell = tableView.dequeueReusableCell(withIdentifier: "Cell",for: indexPath) as! TheWallTableViewCell 
     return cell 
}