-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错误。我如何才能定期打开视图?