我有一个表格视图单元,应该只显示一个标签,但当我运行我的应用程序时,它根本不会显示任何内容。我甚至尝试过在代码中更改文本标签,但仍然一无所获。我也尝试过改变故事板中的单元格背景颜色,但当我实际运行应用程序时,一切都没有改变。我已经完全断开了视图控制器的连接,以查看我的代码是否是问题所在,但仍然没有发生任何事情。因此,从我看到的不是我的代码,而是视图本身。但我可能错了。以下是我的view loks现在的样子:
tableviewdata
//
// TableViewController.swift
// streamingVideo
//
// Created by Connor Woodford on 5/15/18.
// Copyright © 2018 Connor Woodford. All rights reserved.
//
import UIKit
struct Courses: Decodable {
let id: String
let title: String
let location: String
}
class ViewController: UIViewController, UITableViewDelegate, UITableViewDataSource {
var courses = [Courses]()
@IBOutlet weak var arg: UITableView!
override func viewDidLoad() {
super.viewDidLoad()
fetchJSON()
// 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
}
func fetchJSON() {
let urlString = "http://homevideostuff.192.168.1.14.xip.io:8888/getClasses.php"
guard let url = URL(string: urlString) else { return }
URLSession.shared.dataTask(with: url) { (data, _, err) in
DispatchQueue.main.async {
if let err = err {
print("Failed to get data from URL:", err)
return
} else {
print("Loaded URL")
}
guard let data = data else { return }
do {
let decoder = JSONDecoder()
self.courses = try decoder.decode([Courses].self, from: data)
print(self.courses)
} catch let jsonErr {
print("Failed to decode JSON", jsonErr)
}
}
}.resume()
}
// MARK: - Table view data source
func numberOfSections(in tableView: UITableView) -> Int {
// #warning Incomplete implementation, return the number of sections
return 0
}
func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
// #warning Incomplete implementation, return the number of rows
return courses.count
}
func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
let cell = tableView.dequeueReusableCell(withIdentifier: "cell", for: indexPath) as! TableViewCell
let sweet = courses[indexPath.row]
let bgColorView = UIView()
bgColorView.backgroundColor = UIColor.black
cell.selectedBackgroundView = bgColorView
cell.textLabel?.text = "sdafasdfs"
cell.detailTextLabel?.text = sweet.location
print("azDFASDFASDFAS")
return cell
}
}