数据不会显示在带有自定义单元格

时间:2016-03-30 23:04:51

标签: ios swift uitableview cocoa-touch

enter image description here我有一个TabViewController,它指向两个TableViewControllers,我已经制作了第一个自定义单元格。但是,当我运行应用程序时,数据没有加载到单元格中,并且所有内容都是一个没有数据和两个选项卡的空白表格视图,显然当我侧身翻转应用程序时,应用程序崩溃并出现错误:** *由于未捕获的异常终止应用程序' NSInternalInconsistencyException',原因:'无法使用标识符LotteryTableViewCell对单元格进行出列 - 必须为标识符注册一个nib或类或在故事板中连接原型单元格&# 39 ;.我已经尝试使用标识符注册应用程序,但是当我这样做时,我得到一个错误,它无法将表视图转换为我的LotteryTableViewCell。并不是数据是空的,因为我正在打印数据并且它打印出来非常好。此外,我还在storyboard属性中设置了单元格标识符。谢谢,感谢任何帮助。

CellController:

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].firstName!+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 = 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.
}

* /     }

自定义单元格:

import UIKit

class LotteryTableViewCell: UITableViewCell {
// MARK: Properties

@IBOutlet weak var position: UILabel!
@IBOutlet weak var teamLogo: UIImageView!
@IBOutlet weak var teamName: UILabel!
@IBOutlet weak var player: UILabel!
@IBOutlet weak var record: UILabel!

override func awakeFromNib() {
    super.awakeFromNib()
    // Initialization code
}

override func setSelected(selected: Bool, animated: Bool) {
    super.setSelected(selected, animated: animated)

    // Configure the view for the selected state
}

0 个答案:

没有答案
相关问题