【发布时间】:2017-06-02 02:02:43
【问题描述】:
我只是想把这个解析的比特币价格数据加载到表格视图中。我现在将其设置为测试字符串,但这仍然无法正常工作。我已经三次检查了故事板中的所有内容,所以我假设它是这段代码中的内容:
import UIKit
import Alamofire
import AlamofireObjectMapper
import ObjectMapper
class Response: Mappable {
var data: [Amount]?
required init?(map: Map){
}
func mapping(map: Map) {
data <- map["data"]
}
}
class Amount: Mappable {
var data : String?
required init?(map: Map){
}
func mapping(map: Map) {
data <- map["data.amount"]
}
}
let mount = [String]()
let am = [String]()
class ViewController: UIViewController, UITableViewDelegate,
UITableViewDataSource {
@IBOutlet var tableView: UITableView!
func tableView(_ tableView: UITableView, cellForRowAt indexPath:
IndexPath) -> UITableViewCell {
let cell = tableView.dequeueReusableCell(withIdentifier: "cell", for: indexPath)
cell.textLabel?.text = "test"
return cell
}
func Call_bitcoin(){
let url = "https://api.coinbase.com/v2/prices/BTC-USD/buy"
Alamofire.request(url).responseObject{ (response: DataResponse<Amount>) in
let mount = response.result.value
let am = mount?.data
print(am)
}
}
override func viewDidLoad() {
super.viewDidLoad()
Call_bitcoin()
self.tableView.register(UITableViewCell.self, forCellReuseIdentifier: "cell")
tableView.delegate = self
tableView.dataSource = self
self.tableView.reloadData()
}
func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
return am.count
}
func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
print("You tapped cell number \(indexPath.row).")
}
}
【问题讨论】:
-
您好,请改进您的代码格式。很难按原样阅读...谢谢!
-
谢谢,修正了格式。向安东大喊!
-
你的
TableView加载了吗?我的意思是,你能看到细胞分隔线吗?
标签: ios swift uitableview cocoa-touch uikit