私のコレクションビューで特定の配列だけを返すようにしたい。私はそれが "AUDI"から "Chevrolet"または[2 ... 9]にしか戻らないようにしたい。車のメイクと新車の配列を作る、両方とも8の値を持っている。彼らは両方が同じでなければならないが、私にエラーfatal error: Index out of bounds
を与える。私は何を間違えたのですか?NSIndexpath.rowで返す配列から特定の値を取得
var car make = ["Honda","Toyota","AUDI","Bentley","BMW","Mercedes","Buick","Cadillac","KIA","Chevrolet","Corvette","Dodge","FIAT","Ford","GMC","Hyundai","Infiniti","Jaguar","JEEP","LandRover","LEXUS","Mazda","Nissan","RAM","Porsche","Scion","Volkswagen"]
func collectionView(collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int {
return carmake[2...9].count
}
func collectionView(collectionView: UICollectionView, cellForItemAtIndexPath indexPath: NSIndexPath) -> UICollectionViewCell {
let cell = viewcontrol.dequeueReusableCellWithReuseIdentifier("cell", forIndexPath: indexPath) as! jobtypeCollectionViewCell
let newcarmake = carmake[2...9]
cell.title.text = newcarmake[indexPath.row]
return cell
}
ヒント: '2..8'対' 2.9'。 – rmaddy
申し訳ありませんが、タイプミスでした。私はそれを[2 ... 9]に変更します。それでも同じエラーが発生する – Alan