2017-04-16 10 views
-1

ボタンをクリックしたときにテーブルビューに移動するプロジェクトを設計しています。ここでXcode UIBable to UITableView to connect

は、ストーリーボードの写真です:ここでStoryboard

は、ボタンとビューのコードです:

import UIKit 

class CartTableViewController: UITableViewController { 

    override func viewDidLoad() { 
     super.viewDidLoad() 

     // Uncomment the following line to preserve selection between presentations 
     // self.clearsSelectionOnViewWillAppear = false 

     // Uncomment the following line to display an Edit button in the navigation bar for this view controller. 
     // self.navigationItem.rightBarButtonItem = self.editButtonItem() 
    } 

    override func didReceiveMemoryWarning() { 
     super.didReceiveMemoryWarning() 
     // Dispose of any resources that can be recreated. 
    } 

    // MARK: - Table view data source 

    override func numberOfSections(in tableView: UITableView) -> Int { 
     return 1 
    } 

    override func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int { 
     return 0 
    } 

import UIKit 
import os.log 

class MealViewController: UIViewController, UITextFieldDelegate, UIImagePickerControllerDelegate, UINavigationControllerDelegate { 

    //MARK: Properties 
    @IBOutlet weak var nameLabel: UILabel! 
    @IBOutlet weak var priceLabel: UILabel! 
    @IBOutlet weak var photoImageView: UIImageView! 
    @IBOutlet weak var ratingControl: RatingControl! 
    @IBOutlet weak var caloriesLabel: UILabel! 
    @IBOutlet weak var descriptionLabel: UILabel! 


    @IBAction func addToCart(_ sender: UIButton) { 
    } 

、ここでは、テーブルビューのコードであります私はそれをどのように実行すると、それは空白のテーブルを開きます。 numberOfRowsInSectionを変更すると、sigabrtエラーが発生します。どのようにしてビューを定期的に開くだけですか?

答えて

0

関数numberOfRowsInSectionは、指定されたセクションの行数を定義します。 0を定義すると、テーブルは空でなければなりません。あなたが何かを定義する場合は、テーブルビューには、呼び出すことにより、行ごとの具体的なセルを要求します:

func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell 

をあなたのコードに応じて、クラッシュの理由を探すために最初の場所のthats。あなたのコードはそれを表示しません。