Swift xcode错误:“Row.Type没有下标成员”
问题描述:
我想创建一个有12行的表,当你点击一行时,它将用户传送到一个带有按钮列表的新窗口。Swift xcode错误:“Row.Type没有下标成员”
截图错误:enter image description here
类在那里我得到了错误:
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.
}
*/
}
Row类:
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
,而不是通过一键访问。
而且,一般性质的声明骆驼开始降低,即:fileName
和quartzImage
感谢那些摆脱了错误的,我会接受你的答案在8分钟。 – David