[英]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.