来自CollectionViewCell的Segue

时间:2017-04-09 16:13:03

标签: swift uicollectionview uicollectionviewcell

我在swift中多次使用过这个segue,但我无法从collectionViewCell中使用它。为什么????

我可以控制+从单元格拖动到ViewController

这是我的代码

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

    performSegue(withIdentifier: "followSegue", sender: self.postsFollow[indexPath.item].follower)


    print(self.postsFollow[indexPath.item].follower)

    print("You selected cell #\(indexPath.item)!")
}

//Segue to show username in FindUserViewController
override func prepare(for segue: UIStoryboardSegue, sender: Any?) {

    if segue.identifier! == "followSegue" {
        let guest = segue.destination as! FindUserViewController
        guest.pickedUser = sender as! String


        let backItem = UIBarButtonItem()
        backItem.title = "Back"
        navigationItem.backBarButtonItem = backItem

    }
}

0 个答案:

没有答案