我正在使用UICollectionView來顯示內容的應用程序。我想要將單元格或標籤作爲將在Safari中打開的鏈接(http)。Swift:單元格或標籤是一個UI鏈接在UIcollectionView
import UIKit
class ViewController: UIViewController, UICollectionViewDataSource, UICollectionViewDelegate {
var tableData: [String] = ["Data1", "Data2", "Data3"]
var tableImages: [String] = ["img1.png", "img2.jpg", "img3.jpg"]
override func viewDidLoad() {
// Do any additional setup after loading the view, typically from a nib.
}
func collectionView(collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int {
return tableData.count
}
func collectionView(collectionView: UICollectionView, cellForItemAtIndexPath indexPath: NSIndexPath) -> UICollectionViewCell {
let cell: colvwCell = collectionView.dequeueReusableCellWithReuseIdentifier("Cell", forIndexPath: indexPath) as! colvwCell
cell.lblCell.text = tableData[indexPath.row]
cell.imgCell.image = UIImage(named: tableImages [indexPath.row])
return cell
}
func collectionView(collectionView: UICollectionView, didSelectItemAtIndexPath indexPath: NSIndexPath) {
print("Cell \(indexPath.row) selected")
}