2016-05-06 5 views
2

「食事トラッカー」アプリのApple Developerチュートリアル(ここでは、https://developer.apple.com/library/ios/referencelibrary/GettingStarted/DevelopiOSAppsSwift/Lesson8.html#//apple_ref/doc/uid/TP40015214-CH16-SW1)をゆるやかに守っています。それは働いた、私は修正版を作ろうとしている、と私は障害を打っている。すべての機能は、「保存ボタン」を実装して、テーブルビューに新しいアイテムを追加して、巻き戻しセグを使用するまで機能しました。セグは完全に機能し、私が渡したい情報はすべてコンソールに適切に印刷されますが、何らかの理由で新しいセルがテーブルビューに追加されません。ここでXcode swift:私のアンワインドセグが私のテーブルビューに追加されない

は「セグエの準備」のためのコードです:

override func prepareForSegue(segue: UIStoryboardSegue, sender: AnyObject?) { 
    if saveButton === sender { 
     let name = nameTextField.text ?? "" 
     let date = dateLabel.text ?? "" 
     let price = priceTextField.text ?? "" 
     let balance = 100.00 

     // Set the purchase to be passed to PurchaseTableViewController after the unwind segue. 
     purchase = Purchase(name: name, date: date, price: price, balance: balance) 
    } 
} 

そしてここでは、「リストを購入するくつろぎ」のコードです:

@IBAction func unwindToPurchaseList(sender: UIStoryboardSegue) { 
    if let sourceViewController = sender.sourceViewController as? AddPurchaseViewController, purchase = sourceViewController.purchase { 
     // Add a new purchase. 
     let newIndexPath = NSIndexPath(forRow: purchases.count, inSection: 0) 
     purchases.append(purchase) 
     tableView.insertRowsAtIndexPaths([newIndexPath], withRowAnimation: .Bottom) 
    } 
} 

答えて

0

するTryテーブルビューは更新とエンドの更新を開始し

@IBAction func unwindToPurchaseList(sender: UIStoryboardSegue) { 
if let sourceViewController = sender.sourceViewController as? AddPurchaseViewController, purchase = sourceViewController.purchase { 
    // Add a new purchase. 
    let newIndexPath = NSIndexPath(forRow: purchases.count, inSection: 0) 
    tableView.beginUpdates() 
    purchases.append(purchase) 
    tableView.insertRowsAtIndexPaths([newIndexPath], withRowAnimation: .Bottom) 
    tableView.endUpdates() 
} 
} 
関連する問題