gpt4 book ai didi

swift - 无法从 UITableViewCell 调用 PerformSegueWithIdentifier

转载 作者:行者123 更新时间:2023-11-30 12:35:33 26 4
gpt4 key购买 nike

我无法在Infinite3TableViewCell类里面调用performseguewithidentifier。我知道它是 UITableViewCell。那么,如何在Infinite3TableViewCell中调用performseguewithidentifier方法呢?

我想选择一个单元格,然后呈现/继续到新的 ViewController。

//标记:- UITableViewDataSource、UITableViewDelegate最终类 BuyTableViewController:UIViewController {

@IBOutlet weak var tableView: UITableView! {
didSet {
tableView.delegate = self
tableView.dataSource = self
tableView.separatorStyle = .none
}
}

//标记:- UITableViewDataSource、UITableViewDelegate扩展 BuyTableViewController:UITableViewDataSource、UITableViewDelegate {

override func viewDidLoad() {
super.viewDidLoad()

// Uncomment the following line to preserve selection between presentations
// self.clearsSelectionOnViewWillAppear = false

// Uncomment the following line to display an Edit button in the navigation bar for this view controller.
// self.navigationItem.rightBarButtonItem = self.editButtonItem()
}


func numberOfSections(in tableView: UITableView) -> Int {
return 5
}


func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
switch section {
case 0, 1, 2, 3, 4: return 1
default: return 0
}
}


func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
switch indexPath.section {

case 0:
let cell = tableView.dequeueReusableCell(withIdentifier: "Infinite0TableViewCell", for: indexPath)
return cell
case 1:
let cell = tableView.dequeueReusableCell(withIdentifier: InfiniteTableViewCell.identifier) as! InfiniteTableViewCell
return cell
case 2:
let cell = tableView.dequeueReusableCell(withIdentifier: Infinite2TableViewCell.identifier) as! Infinite2TableViewCell
return cell
case 3:
let cell = tableView.dequeueReusableCell(withIdentifier: Infinite3TableViewCell.identifier) as! Infinite3TableViewCell
return cell
case 4:
let cell = tableView.dequeueReusableCell(withIdentifier: Infinite4TableViewCell.identifier) as! Infinite4TableViewCell
return cell
default:
return UITableViewCell()
}
}


func tableView(_ tableView: UITableView, heightForRowAt indexPath: IndexPath) -> CGFloat {
switch indexPath.section {
case 0: return 80
case 1: return 150
case 2: return 120
case 3: return 400
case 4: return 500
default: return 0
}

最终类 CollectionViewCell:UICollectionViewCell {

@IBOutlet weak var imgImage: UIImageView!

@IBOutlet weak var lblName: UILabel!

@IBOutlet weak var imgEffect: UIVisualEffectView!

最终类 Infinite3TableViewCell:UITableViewCell {

static let identifier = "Infinite3TableViewCell"


var nameArray = ["Women's Clothing", "Beauty & Personl Care", "Women's Bags", "Men's Clothing", "Mobile & Gadgets", "Watches", "Home", "Toys", "Home Appliances"]
var imgName = [UIImage(named: "girl"), UIImage(named: "makeup"), UIImage(named: "bags"), UIImage(named: "clothing"), UIImage(named: "mobile"), UIImage(named: "watches"), UIImage(named: "living"), UIImage(named: "toys"), UIImage(named: "tools")]

扩展 Infinite3TableViewCell:UICollectionViewDelegate、UICollectionViewDataSource {

func collectionView(_ collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int{

return nameArray.count

}


func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell{



let cell = collectionView.dequeueReusableCell(withReuseIdentifier: "MyCollectionViewCell", for: indexPath) as! CollectionViewCell
cell.imgImage.image = imgName[indexPath.row]
cell.lblName.text! = nameArray[indexPath.row]
return cell


}


func collectionView(_ collectionView: UICollectionView, didSelectItemAt indexPath: IndexPath) {


print("didSelectItemAt: \(indexPath.item)")

最佳答案

performseguewithidentifier 应该从 UIViewController 或其子类调用。您应该让 UIViewController 了解并调用它。

关于swift - 无法从 UITableViewCell 调用 PerformSegueWithIdentifier,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42918246/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com