ios - Xcode 6 & Swift - 缩进反转?

标签 ios iphone xcode swift

我刚写了这个方法,但出于某种原因,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/

相关文章:

ios - Xcode 10 主线程检查器 : Cordova Camera Plugin

ios - 使用 Alamofire 从 Firebase 检索 JSON

iphone - iOS 自定义按钮和 slider 的免费位图?

ios - 我想从 swift4.0 中的数组中提取 District_NameEng (字典值)

iphone - 是开始学习编写 iPhone 应用程序的好地方吗?

ios - KeyboardWillShowNotification 和 UIAlert

ios - 将react-native从0.59更新到0.61.4后找不到“React/RCTBundleURLProvider.h”文件

ios - 改变 UIView 的大小

xcode - 重新运行失败的单元测试 - Xcode XCTest

objective-c - Xcode 版本 (CFBundleShortVersionString) 和构建 (CFBundleVersion) 之间的区别