gpt4 book ai didi

ios - 仅当我将手机置于横向模式时才会加载表格 View

转载 作者:可可西里 更新时间:2023-11-01 01:36:47 25 4
gpt4 key购买 nike

我有一个自定义表格 View ,当我运行该应用程序时,它显示为空白,就像它尚未加载一样,但是当我将手机倾斜到横向模式时,条目出现了,这对我来说真的没有意义。有什么建议吗?

编辑:这是我的代码

 import UIKit
import Alamofire
import ObjectMapper
class LotteryTableViewController: UITableViewController {
let lotteryMachine = LotteryMachine()

var currentStandings: [Team] = []
var draftStandings: [Team] = []
override func viewDidLoad() {
super.viewDidLoad()

let headers = [
"User-agent": "LotteryMachine/1.0 (nilayneeranjun24@gmail.com)",
]
Alamofire.request(.GET, "https://erikberg.com/nba/standings.json",headers: headers)
.responseJSON { response in
let parentJson = Mapper<Standings>().map(response.2.value)
let standingsArray: [Team] = parentJson!.standing!
self.currentStandings=standingsArray
self.draftStandings=self.lotteryMachine.setPossibleCombinations(standingsArray)
self.draftStandings=self.lotteryMachine.setDraftPositions(self.draftStandings)
print (self.draftStandings.toJSON())
}

}




// 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 numberOfSectionsInTableView(tableView: UITableView) -> Int {

return 1
}

override func tableView(tableView: UITableView, numberOfRowsInSection section: Int) -> Int {

return draftStandings.count
}


override func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {
let cellIdentifier = "LotteryTableViewCell"


let cell = tableView.dequeueReusableCellWithIdentifier(cellIdentifier, forIndexPath: indexPath) as! LotteryTableViewCell


let position = self.draftStandings[indexPath.row].draftingPosition!

let teamName = self.draftStandings[indexPath.row].lastName!
let record = String(self.draftStandings[indexPath.row].won!) + "-" + String(self.draftStandings[indexPath.row].lost!)

let player = "Ben Simmons"
cell.position.text = String(position)
cell.teamName.text = teamName
cell.record.text = String(record)
cell.player.text = player
cell.teamLogo.image = UIImage(named: "lakers")



// Configure the cell...

return cell
}


/*
// Override to support conditional editing of the table view.
override func tableView(tableView: UITableView, canEditRowAtIndexPath indexPath: NSIndexPath) -> Bool {
// Return false if you do not want the specified item to be editable.
return true
}
*/

/*
// Override to support editing the table view.
override func tableView(tableView: UITableView, commitEditingStyle editingStyle: UITableViewCellEditingStyle, forRowAtIndexPath indexPath: NSIndexPath) {
if editingStyle == .Delete {
// Delete the row from the data source
tableView.deleteRowsAtIndexPaths([indexPath], withRowAnimation: .Fade)
} else if editingStyle == .Insert {
// Create a new instance of the appropriate class, insert it into the array, and add a new row to the table view
}
}
*/

/*
// Override to support rearranging the table view.
override func tableView(tableView: UITableView, moveRowAtIndexPath fromIndexPath: NSIndexPath, toIndexPath: NSIndexPath) {

}
*/

/*
// Override to support conditional rearranging of the table view.
override func tableView(tableView: UITableView, canMoveRowAtIndexPath indexPath: NSIndexPath) -> Bool {
// Return false if you do not want the item to be re-orderable.
return true
}
*/

/*
// MARK: - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
override func prepareForSegue(segue: UIStoryboardSegue, sender: AnyObject?) {
// Get the new view controller using segue.destinationViewController.
// Pass the selected object to the new view controller.
}
*/

最佳答案

Alamofire.request 本质上是异步的。因此,当表格首次加载时,请求仍在执行,您的 draftStandings 没有任何数据。当您旋转时,表格会重新加载,到那时 draftStandings 确实已经有表格显示的一些数据。

尝试在请求响应中设置 draftStandings 后添加 tableView.reloadData()

关于ios - 仅当我将手机置于横向模式时才会加载表格 View ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36347579/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com