-1
我正在設計一個項目,我希望它在單擊按鈕時轉到表視圖。Xcode的UIButton UITableView無法連接
這裏是故事板的一個圖:Storyboard
在這裏被用於與該按鈕的視圖的代碼:
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) {
}
和下面是表視圖代碼:
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
}
當我運行它時,它會打開一張空白表。當我更改numberOfRowsInSection時,它會發出sigabrt錯誤。我如何才能定期打開視圖?