我有一个 UITableView
,其原型(prototype)单元格基本上占据了整个页面。我在最底部有一个 UIButton
,点击时应该显示一个弹出式静态 UITableView
。我正在努力解释 cellForRowAtIndexPath
中的弹出 TableView 。
func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {
let result: UITableViewCell
if tableView == self.tableView {
var cell = self.tableView.dequeueReusableCellWithIdentifier("Cell", forIndexPath: indexPath) as! UITableViewCell
cell.textLabel!.text = array[indexPath.row]
result = cell
} else if tableView == self.popUpTableView {
var popUpCell = self.popUpTableView.dequeueReusableCellWithIdentifier("popUpCell", forIndexPath: indexPath) as! UITableViewCell
popUpCell.textLabel!.text = popUpArray[indexPath.row]
result = popUpCell
}
return result
}
我在 return result
处遇到错误,其中 Variable 'result' used before being initialized
,但我在最顶部声明了它。我哪里出错了?
最佳答案
您需要有详尽的选择。结果可能永远不会被初始化,因为您的检查是“if”和“else if”。如果 tableView 不是“self.tableView”或“self.popUpTableView”,会发生什么情况?
简单的解决方法是(如果您只打算拥有这两个)简单地将“else if”更改为简单的“else”。这样结果将始终得到初始化。
关于ios - View Controller 中的两个 TableView : Swift,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31487175/