ios - 类型 [TeamModel] 没有下标成员

标签 ios swift segue subscript

我正在尝试执行从 UICollectionView 单元格到另一个 viewController 的 segue,但是当我尝试传递数据时,Xcode 向我发送了这个错误“类型 [TeamModel] 没有下标成员”。 这是全类

    import UIKit

class AllTeamController: UIViewController, UICollectionViewDataSource, UICollectionViewDelegate
{
    // MARK: properties

    let navigationBar = UINavigationBar()
    let segmentedControl = ADVSegmentedControl()
    @IBOutlet weak var collectionView: UICollectionView!
    @IBOutlet weak var menuButton: UIBarButtonItem!

    // MARK: view method

    override func viewDidLoad()
    {
        super.viewDidLoad()

        DataManager.sharedInstance.loadTeams()

        collectionView!.backgroundColor = UIColor.returnBasicColor("clearGreen")
        collectionView!.decelerationRate = UIScrollViewDecelerationRateFast

        let nib = UINib(nibName: "TeamCell", bundle: nil)
        collectionView.registerNib(nib, forCellWithReuseIdentifier: "teamCell")
    }

    override func didReceiveMemoryWarning()
    {
        super.didReceiveMemoryWarning()
    }

    // MARK: collection view data source and delegate

    func numberOfSectionsInCollectionView(collectionView: UICollectionView) -> Int
    {
        return 1
    }

    func collectionView(collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int
    {
        return DataManager.sharedInstance.teamsArray.count
    }

    func collectionView(collectionView: UICollectionView, cellForItemAtIndexPath indexPath: NSIndexPath) -> UICollectionViewCell
    {
        let cell = collectionView.dequeueReusableCellWithReuseIdentifier("teamCell", forIndexPath: indexPath) as! TeamCell

        let team = DataManager.sharedInstance.teamsArray[indexPath.row]
        cell.teamImage.image = UIImage(named: team.teamImage)
        cell.teamName.text = team.teamName
        cell.teamAdress.text = team.teamAdress
        cell.teamNumberOfChants.text = "\(team.teamNumeberOfChants)"

        return cell
    }

    func collectionView(collectionView: UICollectionView, didSelectItemAtIndexPath indexPath: NSIndexPath)
    {
        performSegueWithIdentifier("toChantController", sender: self)
    }

    // MARK: navigation (segue)

    override func prepareForSegue(segue: UIStoryboardSegue, sender: AnyObject?)
    {
        if (segue.identifier == "toChantController")
        {
            if let indexPath = collectionView.indexPathsForSelectedItems()
            {
                let controller = segue.destinationViewController as! TeamChantViewController
                controller.chant = DataManager.sharedInstance.teamsArray[??????????????????]
            }
        }
    }

DataManager

  import UIKit

class DataManager: NSObject
{
    class var sharedInstance:DataManager
        {
        get {
            struct Static
            {
                static var instance : DataManager? = nil
                static var token : dispatch_once_t = 0
            }
            dispatch_once(&Static.token) { Static.instance = DataManager() }

            return Static.instance!
        }
    }

    // MARK: properties

    var teamsArray: [TeamModel]!
    var settingsArray: [[(name: String, description: String, image: String)]]!

    // MARK: methods

    func loadTeams()
    {
        let juveChant1 = ChantModel(name: "1")
        let juveChant2 = ChantModel(name: "2")
        let juveChant3 = ChantModel(name: "3")
        let juventus = TeamModel(name: "Juventus", adress: "Cori della Juventus", number: 34, colors: ("juvColor","juvColor"), image: "juve_ritaglio", chants: [juveChant1,juveChant2,juveChant3])
        let milan = TeamModel(name: "Milan", adress: "Cori del Milan", number: 12, colors: ("milColor","mlnColor"), image: "milan_ritaglio", chants: [juveChant1,juveChant2,juveChant3])
        let inter = TeamModel(name: "Inter", adress: "Cori dell'Inter", number: 19, colors: ("intColor","intColor"), image: "inter_ritaglio", chants: [juveChant1,juveChant2,juveChant3])
        let roma = TeamModel(name: "Roma", adress: "Cori della Roma", number: 10, colors: ("romColor","romColor"), image: "roma_ritaglio", chants: [juveChant1,juveChant2,juveChant3])
        let napoli = TeamModel(name: "Napoli", adress: "Cori del Napoli", number: 21, colors: ("napColor","napColor"), image: "napoli_ritaglio", chants: [juveChant1,juveChant2,juveChant3])
        let lazio = TeamModel(name: "Lazio", adress: "Cori della lazio", number: 5, colors: ("lazColor","lazColor"), image: "lazio_ritaglio", chants: [juveChant1,juveChant2,juveChant3])
        let fiorentina = TeamModel(name: "Fiorentina", adress: "Cori della Fiorentina", number: 9, colors: ("fioColor","fioColor"), image: "fiorentina_ritaglio", chants: [juveChant1,juveChant2,juveChant3])
        let torino = TeamModel(name: "Torino", adress: "Cori del Torino", number: 11, colors: ("torColor","torColor"), image: "torino_ritaglio", chants: [juveChant1,juveChant2,juveChant3])
        teamsArray = [juventus,milan,inter,roma,napoli,lazio,fiorentina,torino]
    }

    func loadSettings()
    {
        let media = [(name: "Preferiti", description: "I tuoi cori prefriti", image: "heartIcon"),(name: "Stadi d'Italia", description: "Galleria degli stadi italiani", image: "stadiumIcon"),(name: "Mappa", description: "Luoghi di interesse", image: "mapIcon")]
        let social = [(name: "Facebook", description: "Visita la pagina Facebook di iSupporters", image: "facebbokIcon"),(name: "Google+", description: "Visita la pagina Google+ di iSupporters", image: "google+Icon"),(name: "Twitter", description: "Visita la pagina Twitter di iSupporters", image: "twitterIcon"),(name: "Diffondi", description: "Suggerisci iSupporters a un amico", image: "megaphoneIcon")]
        let settings = [(name: "Impostazioni", description: "Impostazioni e restrizioni", image: "settingImage"),(name: "Supporto", description: "Segnala un problea su iSupporters", image: "supportIcon"),(name: "Vota", description: "Dai un voto ad iSupporters su App Store", image: "rateIcon")]
        settingsArray = [media,social,settings]
    }
}

希望有人能解释我哪里做错了!

最佳答案

如评论问题

indexpath[0].row insted indexpath.row: could you explain me?

你正在使用方法

collectionView.indexPathsForSelectedItems()

它返回一个数组,就这么简单所以你需要使用

DataManager.sharedInstance.teamsArray[indexPath[0].row]

关于ios - 类型 [TeamModel] 没有下标成员,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38729416/

相关文章:

ios - 具有核心数据的主从应用程序

ios - 在 iOS 中创建多维数组

ios - 在推送/呈现之前设置 UIViewController

ios - 如何发送符合 UIImagePickerControllerDelegate、UINavigationControllerDelegate 的 UIViewController

具有给定颜色的 IoS Cocoa 填充区域

swift - 选择和取消选择 UICollectionview 以启用按钮

swift - 信号量不等待 ios 中 Web 服务的第二次函数调用

ios - 发送到 setDetailModal 实例的无法识别的选择器

xcode - 如何避免模态 Storyboard无限循环

ios - 在没有 Segue 的 UIViewController 之间移动