【发布时间】:2015-11-04 08:13:01
【问题描述】:
为什么不使用默认值初始化属性?如果我取消注释
// required init?(coder aDecoder: NSCoder)
// {
// super.init(coder: aDecoder)
// }
一切正常。
更新:
看起来与泛型类型“元素”有关的问题,以下代码按预期工作:
import UIKit
class ANTableViewController: UIViewController, UITableViewDataSource, UITableViewDelegate
{
@IBOutlet weak var tableView: UITableView!
var sections: [[SPMenuItem]] = [[SPMenuItem]]()
var a = "qwe"
var configureCellBlock : ((UITableView, NSIndexPath, SPMenuItem) -> UITableViewCell)!
var didSelectElementBlock : ((SPMenuItem) -> Void) = { (element) -> Void in }
func elementForIndexPath(indexPath: NSIndexPath) -> SPMenuItem
{
let elements = sections[indexPath.section]
let element = elements[indexPath.row]
return element
}
// required init?(coder aDecoder: NSCoder)
// {
// super.init(coder: aDecoder)
// }
// MARK: - UITableViewDataSource
func numberOfSectionsInTableView(tableView: UITableView) -> Int { return sections.count }
func tableView(tableView: UITableView, numberOfRowsInSection section: Int) -> Int { return sections[section].count }
func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell
{
let element = elementForIndexPath(indexPath)
assert(configureCellBlock != nil, "configureCellBlock should not be nil!")
let cell = configureCellBlock(tableView, indexPath, element)
return cell
}
}
【问题讨论】:
-
如果您发布代码,而不是粘贴图片,您将吸引更好的受众和更快的解决方案。另外,请详细说明您面临的问题。
-
如果您怀疑调试器的变量窗格显示的内容,然后打印值(通过调试控制台中的命令或右键单击该值并选择打印)。有时值不同。如果是这种情况,打印它们就说明了真相。只是不要问我为什么。
-
如果你从你的代码中删除 debugPrint(sections),它可以工作吗?
-
如预期的那样......顺便说一句,debugPrint 中的崩溃与 v2.1.1 中解决的 swift bug 有关
标签: ios objective-c iphone swift swift2