简体   繁体   English

单击该单元格后,TableView单元格数据将消失。 为什么会这样呢?

[英]TableView Cell data is being disappeared on click on the cell. Why this is happening?

I have created a tableview. 我已经创建了一个tableview。 Then calling an url to get the data and accordingly loading the tableview. 然后调用一个url获取数据并相应地加载tableview。 But whenever i am clicking a cell the data is disappearing. 但是每当我单击一个单元格时,数据就会消失。 I have tried with making userinteractionenabled as false or the selection style as .None. 我尝试将userinteractionenabled设置为false或将选择样式设置为.None。 Still it is not working. 仍然无法正常工作。 Any reason for this? 有什么原因吗?

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
}

Just to round this up, I'm turning my comment into an answer. 只是为了总结一下,我将我的评论变成了答案。

You are return ing the cell from the first line. 您将从第一行return单元格。 That is a fresh cell. 那是一个新鲜的细胞。

The dequeue'd cell you are modifying and throwing away w/o return in the switch. 您正在修改的已出队单元格,并在开关中没有return就丢弃。

The dequeue in case 0 you are throwing away instantly. 如果情况为0,您的出队将立即被丢弃。

This should give you a warning regarding scope ambiguity on the second let cell = , btw. 这应该给您有关第二个let cell = btw范围模糊的警告。

If the problem persists, please update your question and let me know:) 如果问题仍然存在,请更新您的问题,并告诉我:)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 无法单击TableView单元格。 (iOS,自定义单元实现) - Cannot click on TableView cell. (iOS, Custom cell implementation) 在表格视图单元格中添加自动布局约束。 - Adding auto layout constraints in a tableview cell. 单击 tableview 单元格时,将图像传递到另一个视图。 图片取自 json 数据并用 alamofire 初始化 - pass image to another view when clicked on tableview cell. The image is fetched from json data and initialised with alamofire 单个单元格未发生TableView单元格扩展 - TableView cell expansion not happening for single cell 一个tableView单元中有两个collectionViews。 collectionViews没有出现 - Two collectionViews in one tableView Cell. collectionViews not appearing 自定义tableview单元格中的UITextField。 点击单元格/文本字段时显示pickerview - UITextField in custom tableview cell. Show pickerview when cell/textfield is tapped 在tableview单元格中显示列数据-为什么不创建和填充我的表单元格? - Display column data in tableview cell - Why aren't my table cells being created and populated? 为什么tableView单元格不动态? - Why is tableView cell not dynamic? 更新 TableView 单元格数据 - Update TableView cell data 表格视图未使用原型单元 - Prototype Cell not being used by tableview
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM