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