1
我在两个UITableViews
之上有一个分段控件,其中一个层叠在另一个之上。当segmentedControl.selectedSegmentIndex == 1
其中一个表视图将隐藏。但是,问题是我无法在我的一个cellForRowAtIndexPath
函数中配置第二个表视图的自定义单元格。我不断收到:Variable 'cell' used before being initialized
。使用分段控件返回cellForRowAtIndexPath中的两个单元格
func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {
switch segmentedControl.selectedSegmentIndex {
case 0:
var cell = tableView.dequeueReusableCellWithIdentifier("CellOne", forIndexPath: indexPath) as! CellOne
return cell
case 1:
var cellTwo = tableView.dequeueReusableCellWithIdentifier("CellTwo", forIndexPath: indexPath) as! CellTwo
return cellTwo
default:
var cell: UITableViewCell
return cell
}
}
那么解决方案是什么? – chicobermuda
@dprek我更新了我的答案。我在代码中做了一个假设,总是选择一些段,所以我们总是显示CellOne或CellTwo,并且没有任何其他选项。 –
我该如何配置,即CellOne中的标签与CellTwo中的UIImageView? – chicobermuda