Swift xcode 错误:"Row.Type has no subscript members"



我正在尝试创建一个包含 12 行的表,当您单击一行时,它会将用户传输到带有按钮列表的新窗口。

错误屏幕截图:在此处输入图像描述

我收到错误的类:

import UIKit
class RowTable
{

    func viewDidLoad() {
       viewDidLoad()
        // Uncomment the following line to preserve selection between presentations
        // self.clearsSelectionOnViewWillAppear = false
        // Uncomment the following line to display an Edit button in the navigation bar for this view controller.
        // self.navigationItem.rightBarButtonItem = self.editButtonItem()
    }
    func didReceiveMemoryWarning() {
       didReceiveMemoryWarning()
        // Dispose of any resources that can be recreated.
    }
    // MARK: - Table view data source
    func numberOfSectionsInTableView(tableView: UITableView) -> Int {
        // #warning Incomplete implementation, return the number of sections
        return 1
    }
    func tableView(tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
        // #warning Incomplete implementation, return the number of rows
        return 12
    }

    func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {
        let cell = tableView.dequeueReusableCellWithIdentifier("FileSlot", forIndexPath: indexPath)
        2
        cell.textLabel?.text = Row[indexPath.row]["FileName"] //this is where i got the error that said Row.Type has no subscript members
        let enabledSwitch = UISwitch(frame: CGRectZero) as UISwitch
        enabledSwitch.on = true
        enabledSwitch.addTarget(self, action: "switch1:", forControlEvents: UIControlEvents.ValueChanged)
        enabledSwitch.tag = indexPath.row
        cell.accessoryView = enabledSwitch
        return cell
    }

    /*
    // Override to support conditional editing of the table view.
    override func tableView(tableView: UITableView, canEditRowAtIndexPath indexPath: NSIndexPath) -> Bool {
        // Return false if you do not want the specified item to be editable.
        return true
    }
    */
    /*
    // Override to support editing the table view.
    override func tableView(tableView: UITableView, commitEditingStyle editingStyle: UITableViewCellEditingStyle, forRowAtIndexPath indexPath: NSIndexPath) {
        if editingStyle == .Delete {
            // Delete the row from the data source
            tableView.deleteRowsAtIndexPaths([indexPath], withRowAnimation: .Fade)
        } else if editingStyle == .Insert {
            // Create a new instance of the appropriate class, insert it into the array, and add a new row to the table view
        }    
    }
    */
    /*
    // Override to support rearranging the table view.
    override func tableView(tableView: UITableView, moveRowAtIndexPath fromIndexPath: NSIndexPath, toIndexPath: NSIndexPath) {
    }
    */
    /*
    // Override to support conditional rearranging of the table view.
    override func tableView(tableView: UITableView, canMoveRowAtIndexPath indexPath: NSIndexPath) -> Bool {
        // Return false if you do not want the item to be re-orderable.
        return true
    }
    */
    /*
    // MARK: - Navigation
    // In a storyboard-based application, you will often want to do a little preparation before navigation
    override func prepareForSegue(segue: UIStoryboardSegue, sender: AnyObject?) {
        // Get the new view controller using segue.destinationViewController.
        // Pass the selected object to the new view controller.
    }
    */
}

行类:

import UIKit

let rows = [
    Row(FileName: "File slot 1",
        QuartzImage: "Image slot 1"),
    Row(FileName: "File slot 2",
        QuartzImage: "Image slot 2"),
    Row(FileName: "File slot 3",
        QuartzImage: "Image slot 3"),
    Row(FileName: "File slot 4",
        QuartzImage: "Image slot 4"),
    Row(FileName: "File slot 5",
        QuartzImage: "Image slot 5"),
    Row(FileName: "File slot 6",
        QuartzImage: "Image slot 6"),
    Row(FileName: "File slot 7",
        QuartzImage: "Image slot 7"),
    Row(FileName: "File slot 8",
        QuartzImage: "Image slot 8"),
    Row(FileName: "File slot 9",
        QuartzImage: "Image slot 9"),
    Row(FileName: "File slot 10",
        QuartzImage: "Image slot 10"),
    Row(FileName: "File slot 11",
        QuartzImage: "Image slot 11"),
    Row(FileName: "File slot 12",
        QuartzImage: "Image slot 12")]
class Row
{
    ///// enum Type: String {
    // }
    var FileName: String
    var QuartzImage: String
    // var type: Type
    // var shortDescription: String
    // var longDescription: String
    init(FileName: String, QuartzImage: String) {
        self.FileName = FileName
        self.QuartzImage = QuartzImage
}
}

使用:let filename = rows[indexPath.row].FileName而不是通过密钥访问。

此外,通常属性声明为骆驼大小写从较低开始,即:fileNamequartzImage

相关内容

最新更新