2016-06-27 4 views
0

私は自分のアプリケーションをセットアップしてViewViewrollerにセルを追加できるようにしていますが、そのセルはtableViewに表示されますが、セルをクリックすると、情報。ここでは...コードである削除するためにスワイプするときに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に変更しようとしました。私がスワイプしたときには全く拡張されませんでしたが、コードの一部がそれに影響を与えるとは思っていませんでした。スワイプされると、セルの通常のサイズに戻ります。 –

関連する問題