【发布时间】:2019-10-22 15:26:52
【问题描述】:
我创建了一个UITableView 并希望将我的结果从 api 显示到UITableView 中的单元格。有一个单元格类,其中包含标签的出口,但单元格中没有显示任何内容。结果显示在控制台中,但不在单元格标签中
我已尝试删除和添加新约束。 我还添加了一个按钮来重新加载 UITableView 的内容,但没有任何帮助。
func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
return 1
}
func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
let cell = tableView.dequeueReusableCell(withIdentifier: "customCell", for: indexPath) as! customCellTableViewCell
var result: String!
Alamofire.request(booksUrl, method: .get).responseJSON { (response) in
if response.result.isSuccess{
let bookJSON : JSON = JSON(response.result.value)
let tempResult = bookJSON["items"][0]["volumeInfo"]["title"].stringValue
result = tempResult
print(tempResult)
}
}
cell.bookNameLabel?.text = result
return cell
}
【问题讨论】:
标签: ios swift xcode api uitableview