【发布时间】:2018-07-21 23:16:14
【问题描述】:
我必须查看控制器。第一个是表格视图,第二个是第二个详细视图中的集合视图。我创建了一组图像数组。我希望单击单元格表并将一组图像传递给集合视图。我用数组数组定义了一个文件模型。我还为单元格表和单元格集合视图定义了另外两个控制器。
问题:我无法传递这个数组图像数组。我确实使用 prepare for segue 将字符串数组传递给了详细信息中的 textview。沃尔克在那里,我将非常感谢您的帮助。可以看一下GitHub中的项目:https://github.com/ricardovaldes/hotelesWithIos9
此刻,当我点击表格单元格时,我会得到一些不同数组的图片,无论我点击哪个单元格,总是相同的图片。
import UIKit
class DetailVCViewController: UIViewController, UICollectionViewDelegate, UICollectionViewDataSource {
let hotel = Hotel()
var myDescription = ""
@IBOutlet weak var myCollection: UICollectionView!
@IBOutlet weak var label: UILabel!
@IBOutlet weak var hotelDescription: UITextView!
override func viewDidLoad() {
super.viewDidLoad()
hotelDescription.text = myDescription
}
func collectionView(_ collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int {
return hotel.array.count
}
func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell {
let cell = myCollection.dequeueReusableCell(withReuseIdentifier: "collectionCell", for: indexPath) as! CollectionCellCollectionViewCell
cell.cellImage.image = UIImage(named: hotel.array[indexPath.row][indexPath.row])
return cell
}
@IBAction func reservar(_ sender: UIButton) {
}
}
import UIKit
class ViewController: UIViewController, UITableViewDataSource, UITableViewDelegate {
@IBOutlet weak var myTable: UITableView!
let hotel = Hotel()
override func viewDidLoad() {
super.viewDidLoad()
// Do any additional setup after loading the view, typically from a nib.
let cell = UINib(nibName: "TableViewCell", bundle: nil)
myTable.register(cell, forCellReuseIdentifier: "tableCell")
}
func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
return hotel.hotelNames.count
}
func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
let cell = myTable.dequeueReusableCell(withIdentifier: "tableCell", for: indexPath) as! TableViewCell
cell.hotelName.text = hotel.hotelNames[indexPath.row]
cell.hotelImage.image = UIImage(named: hotel.hotelImages[indexPath.row])
cell.hotelImage.contentMode = .scaleToFill
return cell
}
func tableView(_ tableView: UITableView, heightForRowAt indexPath: IndexPath) -> CGFloat {
return 250
}
func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
performSegue(withIdentifier: "mySegue", sender: self)
}
override func prepare(for segue: UIStoryboardSegue, sender: Any?) {
let index = myTable.indexPathForSelectedRow
let indexNumber = index?.row
let secondVC = segue.destination as! DetailVCViewController
secondVC.myDescription = hotel.description[indexNumber!]
}
}
【问题讨论】:
-
表格中的一些代码和细节:
标签: arrays swift uicollectionview tableview