我的swift程序一直出现这个错误,我使用PHP和MySQL作为数据库.我将数据从数据库显示到tableview.它以前工作但经过几次运行到模拟器后,我一直有同样的错误
class Home: UIViewController, UITableViewDelegate, UITableViewDataSource {
@IBOutlet weak var btnaddclass: UIButton!
@IBOutlet var tableView: UITableView!
var values: NSArray = []
func get(){
let url = NSURL(string: "http://localhost/show_db.php")
let data = NSData(contentsOf: url! as URL)
values = try! JSONSerialization.jsonObject(with: data! as Data, options:JSONSerialization.ReadingOptions.mutableContainers)as! NSArray
tableView.reloadData()
}
func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
return values.count
}
func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
let cell = tableView.dequeueReusableCell(withIdentifier: "cell", for: indexPath) as! SpecialCell
let maindata …Run Code Online (Sandbox Code Playgroud)