2016-06-27 3 views
0

내 app을 설정하여 TableView에 셀이 표시되는 ViewController에 셀을 추가 할 수 있지만 셀을 클릭하면 더 많이 표시됩니다. 정보. 여기에 ... 코드입니다삭제하려면 스 와이프 때 tableViewCell을 얻는 방법

class ViewController: UIViewController, UITableViewDelegate, UITableViewDataSource { 

var selectedIndexPath: NSIndexPath? = nil 

override func viewDidLoad() { 
    super.viewDidLoad() 

    tableView.registerNib(UINib(nibName: "CustomViewCell", bundle: nil), forCellReuseIdentifier: "Cell") 

} 

func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell { 

    let cell = self.tableView.dequeueReusableCellWithIdentifier("Cell", forIndexPath: indexPath) as! CustomViewCell 

    cell.clipsToBounds = true 

    return cell 

} 

func tableView(tableView: UITableView, heightForRowAtIndexPath indexPath: NSIndexPath) -> CGFloat { 

    if selectedIndexPath != nil { 

     if indexPath == selectedIndexPath { 
      return 140 
     } else { 
      return 38 
     } 

    } else { 
     return 38 
    } 

} 

func tableView(tableView: UITableView, didSelectRowAtIndexPath indexPath: NSIndexPath) { 
    // New 
    switch selectedIndexPath { 
    case nil: 
     selectedIndexPath = indexPath 
    default: 
     if selectedIndexPath! == indexPath { 
      selectedIndexPath = nil 
     } else { 
      selectedIndexPath = indexPath 
     } 
    } 

    tableView.reloadRowsAtIndexPaths([indexPath], withRowAnimation: .Automatic) 

} 

모든 것은 확장하고 삭제 나는 슬쩍 셀을 구성하는 것을 제외하고 셀에 대한 폐쇄하지만 삭제 슬쩍 때 셀이 단지 확장과 함께 잘 작동합니다. Heres는 코드 : 나는 스 와이프하여 삭제 할 때이 같은 셀 확장 할 해달라고

func tableView(tableView: UITableView, editActionsForRowAtIndexPath indexPath: NSIndexPath) -> [UITableViewRowAction]? { 


    let deleteAction = UITableViewRowAction(style: UITableViewRowActionStyle.Default, title: "Delete") { (action , indexPath) -> Void in 
     self.editing = false  
     let appDelegate = UIApplication.sharedApplication().delegate as! AppDelegate 
     let moc = appDelegate.managedObjectContext 
     moc.deleteObject(self.events[indexPath.row]) 
     appDelegate.saveContext()    
     self.events.removeAtIndex(indexPath.row) 
     tableView.reloadData() 

    } 

    return [deleteAction] 

} 

Before swipe to delete

After swipe to delete

, 어떤 아이디어?

답변

1

생각해 보면 은 세포를 확장하고있는 사람일지도 모릅니다. 다음과 같이 말하고 있습니다.

func tableView(tableView: UITableView, heightForRowAtIndexPath indexPath: NSIndexPath) -> CGFloat { 
    if indexPath == selectedIndexPath { 
     return 140 
    } 
} 

삭제를 위해 스 와이프 중에 해당 메서드가 호출되고 있습니까? 찾아 디버깅을 사용하십시오. 그럴 경우 해당 코드를 다시 작성해야합니다. 삭제를 위해 스 와이프 중일 경우에 대비하여 140을 반환하지 마십시오.

+0

나는 140을 38로 변경하려고 시도했다. 내가 훔 쳤을 때 전혀 확장되지 않겠지 만 코드의 일부가 그것에 영향을 미쳤다고 나는 생각하지 않는다. 셀을 스 와이프하면 정상 크기로 돌아갑니다. –

관련 문제