1.
class ViewController: UIViewController, UITableViewDelegate, UITableViewDataSource{
@IBOutlet weak var tblview: UITableView!
var fruit = ["tomato","mango","orange","banana","apple"]
var fruitsimg : NSMutableArray = ["tomato_small.png","images-1.jpg","fruit-1218149_960_720.png","4164249-fruit-images.jpg","5135668-fruit-images.jpg",]
override func viewDidLoad() {
super.viewDidLoad()
// Do any additional setup after loading the view, t/Users/agile-14/Desktop/4164249-fruit-images.jpgypically from a nib.
}
func tableView(_ tableView: UITableView, heightForHeaderInSection section: Int) -> CGFloat {
return 20
}
func tableView(_ tableView: UITableView, heightForFooterInSection section: Int) -> CGFloat {
return 20
}
func tableView(_ tableView: UITableView, willDisplayHeaderView view: UIView, forSection section: Int)
{
view.tintColor = UIColor.red
}
func tableView(_ tableView: UITableView, willDisplayFooterView view: UIView, forSection section: Int) {
view.tintColor = UIColor.yellow
}
func tableView(_ tableView: UITableView, titleForHeaderInSection section: Int) -> String? {
return fruit[section]
}
func numberOfSections(in tableView: UITableView) -> Int {
return 1
}
func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
return fruit.count
}
func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
let cell = tableView.dequeueReusableCell(withIdentifier: "cell", for: indexPath)as! TableViewCell1
cell.lbl1.text = fruit[indexPath.row]
cell.img1.image = UIImage(named: fruitsimg[indexPath.row] as! String)
cell.img1.layer.cornerRadius = cell.img1.layer.frame.height/2
cell.img1.clipsToBounds = true
cell.img1.layer.borderWidth = 2
cell.img1.layer.borderColor = UIColor.black.cgColor
return cell
}
func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
var vc1 = storyboard?.instantiateViewController(withIdentifier: "collViewController") as! collViewController
vc1.arr = fruitsimg
//vc1.str = fruitsimg[indexPath.row]
self.navigationController?.pushViewController(vc1, animated: true)
}
2.
class collViewController: UIViewController, UICollectionViewDelegate, UICollectionViewDataSource{
@IBOutlet var coll: UICollectionView!
var arr : NSMutableArray = []
override func viewDidLoad() {
super.viewDidLoad()
// Do any additional setup after loading the view.
}
func collectionView(_ collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int {
return arr.count
}
func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell {
let cell = coll.dequeueReusableCell(withReuseIdentifier: "cell", for: indexPath)as! CollectionViewCell1
cell.img2.image = UIImage(named: arr[indexPath.row] as! String)
return cell
}
感謝您solution.But居然在我的收藏view.swift在我tableviewcontroller.swift我必須分配'VAR TYPEID = 「」 '然後在我的集合視圖vc ..on type Id =的意思是..我必須動態顯示。因爲我現在有一些5數據和5 typ類型的id.So可能是5數據可以chnage到50未來的知道。那麼我如何分配類型,如果價值? –
user5513630
而且..我需要顯示名稱,描述基於我的單元格在集合視圖中的點擊操作...所以通過這個執行seague ....我也可以顯示名稱,描述.....當我點擊任何單元名稱? – user5513630
在集合視圖上單擊您將具有視圖的位置。從那個位置你可以分配一個id給那個typeId變量。你必須有一個類型的列表? 。你能告訴我你如何將數據提供給收藏視圖? – imagngames