2016-09-20 11 views
-1

segueを使用してテーブルビューコントローラ間でデータを転送する必要がありますか? editActionsForRowAtIndexPathメソッドで3つのアクションを書きましたが、そのうち2つが別のテーブルビューコントローラ(元のテーブルビューコントローラから削除している間)にデータを転送できることが期待されます。私が見るすべての答えがセグーについてですか?セグのないテーブルビュー間でデータを転送しますか?

誰かが私にヒントを与えることができたら、私は感謝しています、私はここにこだわっています、ちょうど私のためのヒントで十分です!

ありがとうございます。

私のコードがダウンして以下の通りです:

override func tableView(tableView: UITableView, editActionsForRowAtIndexPath indexPath: NSIndexPath) -> [UITableViewRowAction]? { 
    let moveAction = UITableViewRowAction(style: .Default, title: "Move") { (action, indexPath) in 
    let moveMenu = UIAlertController(title: nil, message: "Move to", preferredStyle: .ActionSheet) 

     // I need to write two handler to handle the movements 
     let cancelationAction = UIAlertAction(title: "Move to Cancelation List", style: .Default, handler: moveToCancelation) 
     let achievementAction = UIAlertAction(title: "Move to Achievement List", style: .Default, handler: moveToAchievement) 
     let cancel = UIAlertAction(title: "Cancel", style: .Cancel, handler: nil) 
     moveMenu.addAction(cancelationAction) 
     moveMenu.addAction(achievementAction) 
     moveMenu.addAction(cancel) 
     self.presentViewController(moveMenu, animated: true, completion: nil) 
    } 

    let deleteAction = UITableViewRowAction(style: .Default, title: "Delete") { (action, indexPath) in 
     // delete items from data source 
     self.wishList.removeAtIndex(indexPath.row) 
     self.saveWishList() 
     self.tableView.deleteRowsAtIndexPaths([indexPath], withRowAnimation: .Fade) 
    } 

    moveAction.backgroundColor = UIColor.lightGrayColor() 
    deleteAction.backgroundColor = UIColor.redColor() 

    return [moveAction, deleteAction] 
} 

答えて

0

1週間過ぎて、私は今直面していたことを実装しました。 問題は、はい、私たちはセグを必要としています。これ以前は、実際のボタンや別のビューからセグを作ることができると思っていましたが、実際には、ビューコントローラから別のビューコントローラどの要素がセグをアクティブにするか指定することなく。だから私は何ですか、 2つのビューコントローラの間にセグを作成し、上記のハンドラを書いて、特定の識別子でセグを実行してください。 私はこれが新しい人を助けることを願っています。 、あなたが正しいです

// Implementing the delete and move to function 
override func tableView(tableView: UITableView, editActionsForRowAtIndexPath indexPath: NSIndexPath) -> [UITableViewRowAction]? { 
    let moveAction = UITableViewRowAction(style: .Default, title: "Move") { (action, indexPath) in 
    let moveMenu = UIAlertController(title: nil, message: "Move to", preferredStyle: .ActionSheet) 

     // I need to write two handler to handle the movements 
     let cancelationAction = UIAlertAction(title: "Move to Cancelation List", style: .Default, handler: { 
      (action: UIAlertAction) in 
     self.performSegueWithIdentifier("MoveToCancelationList", sender: tableView.cellForRowAtIndexPath(indexPath)) 
     }) 
     let achievementAction = UIAlertAction(title: "Move to Achievement List", style: .Default, handler: { 
      (action: UIAlertAction) in 
      self.performSegueWithIdentifier("MoveToAchievementList", sender: tableView.cellForRowAtIndexPath(indexPath)) 
     }) 
     let cancel = UIAlertAction(title: "Cancel", style: .Cancel, handler: nil) 
     moveMenu.addAction(cancelationAction) 
     moveMenu.addAction(achievementAction) 
     moveMenu.addAction(cancel) 
     self.presentViewController(moveMenu, animated: true, completion: nil) 
    } 

    let deleteAction = UITableViewRowAction(style: .Default, title: "Delete") { (action, indexPath) in 
     // delete items from data source 
     self.wishListBand.removeAtIndex(indexPath.row) 
     self.saveWishListBand() 
     self.tableView.deleteRowsAtIndexPaths([indexPath], withRowAnimation: .Fade) 
    } 

    moveAction.backgroundColor = UIColor.lightGrayColor() 
    deleteAction.backgroundColor = UIColor.redColor() 

    return [moveAction, deleteAction] 
} 
2

それは一般的にシーン間の相互作用を示すために、ストーリーボードを使用するのが最も簡単ですので、他の答えはseguesの面でこれを議論し、seguesは、それらの相互作用をカプセル化します。あなたの例が示唆しているように、コードですべてをやっているのなら、セグは無意味です。その代わりに、宛先ビューコントローラでプロパティを手動で設定するだけで済みます。

+0

多分私は物事がより複雑になっています:

私の新しいコードはdownblowです。私はsegueを使用しようとします。ありがとう! –

関連する問題