Within my app i have a UIButton
(avatar button which shows a profileVC) within a UICollectionView
this button shows up in about 4-5 other views. I'm currently adding the target within cellForItemAtIndexPath
in each view controller and pushing the view from a public function pushNewViews
. I was wondering if they was a better way to do this? (less repetition)
class ShotsViewController: UIViewController{
//CollectionView
override func collectionView(collectionView: UICollectionView, cellForItemAtIndexPath indexPath: NSIndexPath) -> UICollectionViewCell {
let cell = collectionView.dequeueReusableCellWithReuseIdentifier("cell2", forIndexPath: indexPath) as! mainCell
cell.userImg.addTarget(self, action: #selector(ShotsViewController.showProfileView(_:)), forControlEvents: .TouchUpInside)
}
//Target Func
func showProfileView(sender: AnimatableButton) {
let profileUser = shots[sender.tag].user
pushNewViews.showProfileViewController(profileUser, navigation: navigationController!, storyboard: storyboard!)
}
}
class pushNewViews{
class func showProfileViewController(user: User, navigation: UINavigationController, storyboard: UIStoryboard){
let vc = storyboard.instantiateViewControllerWithIdentifier("profileView") as! ProfileViewController
vc.user = user
navigation.pushViewController(vc, animated: true)
}
}