在我的应用程序中我想在UIViewController中显示两个表视图,但我有致命错误:致命错误:在展开可选值时意外发现nil
有人可以帮我这个吗?
这是uiview的完整代码
类MyPropertiesViewController:UIViewController,UITableViewDelegate,UITableViewDataSource {
//table view extended
@IBOutlet weak var extandedTableViex: UITableView!
// table view standart
@IBOutlet weak var standartTableView: UITableView!
//list of data
let stdlist = ["1","2","3", "4","5","6","7","8","9"]
let Extlist = ["E1","E2" ]
//单元格标识符 让stdcellIdentifier =“stdcell”
let extcellIdentifier = "extcell"
override func viewDidLoad() {
super.viewDidLoad()
standartTableView.delegate = self
standartTableView.dataSource = self
standartTableView.delegate = self
standartTableView.dataSource = self
standartTableView.scrollEnabled = false
extandedTableViex.scrollEnabled = false
self.standartTableView.registerClass(GuaranteeCell.self, forCellReuseIdentifier: stdcellIdentifier)
self.extandedTableViex.registerClass(GuaranteeCell.self, forCellReuseIdentifier: extcellIdentifier)
}
//count cell
func tableView(tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
if tableView == standartTableView {
return self.stdlist.count;
} else {
return self.Extlist.count;
}
}
// add cell
func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {
if tableView == standartTableView {
let cell:GuaranteeCell = self.standartTableView.dequeueReusableCellWithIdentifier(stdcellIdentifier) as! GuaranteeCell
print("list-element " + self.stdlist[indexPath.row])
print(indexPath.row)
cell.guaranteeLabel.text = self.stdlist[indexPath.row]
return cell
} else {
let cell2:GuaranteeCell = self.extandedTableViex.dequeueReusableCellWithIdentifier(extcellIdentifier) as! GuaranteeCell
cell2.guaranteeLabel.text = String(self.Extlist[indexPath.row])
return cell2
}
}
func tableView(tableView: UITableView, didSelectRowAtIndexPath indexPath: NSIndexPath) { }
override func viewWillAppear(animated: Bool) {
super.viewWillAppear(animated)
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
// Dispose of any resources that can be recreated.
}
}
感谢
答案 0 :(得分:0)
检查您的单元格类是否真的是GuaranteeCell(可能是错误)