[英]Cannot click on TableView cell. (iOS, Custom cell implementation)
[英]TableView Cell data is being disappeared on click on the cell. Why this is happening?
我已經創建了一個tableview。 然后調用一個url獲取數據並相應地加載tableview。 但是每當我單擊一個單元格時,數據就會消失。 我嘗試將userinteractionenabled設置為false或將選擇樣式設置為.None。 仍然無法正常工作。 有什么原因嗎?
class CheckInTableViewController: UITableViewController {
var flightInfo : [Flight]!
var multipleChoiceQuestion : [MultipleChoiceQuestion]!
var question : [String] = [String]()
var answer : [[String]] = [[String]]()
var correctAnswer: [Int] = [Int]()
override func viewDidLoad() {
super.viewDidLoad()
loadData()
}
func loadData(){
Request.CheckInFlight().execute().validate().responseJSON { (request, _, data, error)
-> Void in
if error != nil {
print("error")
}
else{
self.flightInfo = Response.flightsFromJSON(data)
self.multipleChoiceQuestion = self.flightInfo[0].checkInUpdate.checkInTest.multipleChoiceQuestion
for questionNew in self.multipleChoiceQuestion {
self.question.append(questionNew.question)
self.answer.append(questionNew.answerArray)
self.correctAnswer.append(questionNew.correctAnswerId)
}
self.tableView.reloadData()
}
}
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
// Dispose of any resources that can be recreated.
}
// MARK: - Table view data source
override func numberOfSectionsInTableView(tableView: UITableView) -> Int {
// #warning Incomplete implementation, return the number of sections
return 1
}
override func tableView(tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
// #warning Incomplete implementation, return the number of rows
if flightInfo != nil {
return flightInfo.count + 1
}
return 1
}
override func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {
let cell = UITableViewCell()
switch indexPath.row {
case 0: _ = tableView.dequeueReusableCellWithIdentifier("headercell", forIndexPath: indexPath) as! CheckInHeaderTableViewCell
default:
let cell = tableView.dequeueReusableCellWithIdentifier("datacell", forIndexPath: indexPath) as! CheckInTableViewCell
cell.flightNumber.text = flightInfo[indexPath.row - 1].fullFlightId
cell.departureCity.text = flightInfo[indexPath.row - 1].departureInfo!.airport.iataCode
cell.departureDate.text = dateFormatter(flightInfo[indexPath.row - 1].departureInfo!.scheduledDateTime)
cell.departureTime.text = flightInfo[indexPath.row - 1].departureInfo!.scheduledDateTime.flightTimeString()
cell.arrivalCity.text = flightInfo[indexPath.row - 1].arrivalInfo!.airport.iataCode
cell.arrivalDate.text = dateFormatter(flightInfo[indexPath.row - 1].arrivalInfo!.scheduledDateTime)
cell.arrivalTime.text = flightInfo[indexPath.row - 1].arrivalInfo!.scheduledDateTime.flightTimeString()
}
return cell
}
只是為了總結一下,我將我的評論變成了答案。
您將從第一行return
單元格。 那是一個新鮮的細胞。
您正在修改的已出隊單元格,並在開關中沒有return
就丟棄。
如果情況為0,您的出隊將立即被丟棄。
這應該給您有關第二個let cell =
btw范圍模糊的警告。
如果問題仍然存在,請更新您的問題,並告訴我:)
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.