我刚写了这个方法,但出于某种原因,Xcode 正在反转缩进。我在某处遇到语法错误还是错误?
这是它正在做的:
import UIKit
class ChecklistViewController: UITableViewController {
override func viewDidLoad() {
super.viewDidLoad()
// Do any additional setup after loading the view, typically from a nib.
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
// Dispose of any resources that can be recreated.
}
override func tableView(tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
return 1
}
override func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {
let cell = tableView.dequeueReusableCellWithIdentifier("ChecklistItem") as UITableViewCell
let label = cell.viewWithTag(1000) as UILabel
if indexPath.row == 0 {
label.text = "Walk the dog"
} else if indexPath.row == 1 {
label.text == "Brush my teeth"
} else if indexPath.row == 2 {
label.text = "Learn iOS development"
} else if indexPath.row == 3 {
label.text = "Soccer practice"
} else if indexPath.row == 4 {
label.text = "Eat ice cream"
}
return cell
}
override func tableView(tableView: UITableView, didSelectRowAtIndexPath indexPath: NSIndexPath) {
if let cell = tableView.cellForRowAtIndexPath(indexPath) {
if cell.accessoryType == .None {
cell.accessoryType = .Checkmark
} else {
cell.accessoryType = .None
}
}
tableView.deselectRowAtIndexPath(indexPath, animated: true)
}
}
它只对 cellForRowAtIndexPath
之后的方法执行此操作。它一定是语法问题吧..?
最佳答案
您在最后一个方法声明中有 override func override func
。当您键入 override func
然后让 Xcode 自动完成方法名称时,就会发生这种情况——它会添加自己的 override func
然后您就会遇到问题。
关于ios - Xcode 6 & Swift - 缩进反转?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26163545/