ios - Swift 3 pass values to Controller on UICollectionViewCell button click -
i beginner in ios development , have implemented following screen using uicollectionview :
collectionviewcell file code is:
import uikit class eventcell: uicollectionviewcell{ var classevent: event? @iboutlet weak var eventtitle: uilabel! @iboutlet weak var eventteams: uilabel! @iboutlet weak var eventtime: uilabel! @iboutlet weak var eventteamoneimage: uiimageview! @iboutlet weak var eventteamtwoimage: uiimageview! @iboutlet weak var leaderboardbutton: uibutton! var datasourceitem: any?{ didset{ guard let event = datasourceitem as? event else { return } classevent = event eventtitle.text = "match \(event.matchno) (\(event.matchstage))" eventteams.text = "\(event.teamone.nameattr) vs \(event.teamtwo.nameattr)" eventtime.text = "\(event.geteventlocktimeasstring())" eventteamoneimage.loadimageusingcache(withurl: event.teamone.flagphoto) eventteamtwoimage.loadimageusingcache(withurl: event.teamtwo.flagphoto) leaderboardbutton.addtarget(self, action: #selector(handleleaderboardclick), for: .touchupinside) } } @ibaction func leaguebutton(_ sender: any) { } weak var delegate: homecontrollerdelegate? func handleleaderboardclick() { if let matchid = classevent?.id { print(matchid) delegate?.clickonleaderboard(matchid: matchid) } } }
now on click on leaderboard button(icon 1,2,3) open new leaderboard controller , pass matchid classevent.id
how can pass values new controller? , best way that.
you can pass match id via segue:
in leaderboard controller set property:
var matchid:int?
set segue between controller , add identifier: on click leaderboard button:
self.performseguewithidentifier("yoursegueidentifier", sender: self)
add segue method:
override func prepareforsegue(segue: uistoryboardsegue, sender: anyobject!) { if segue,identifier == "yoursegueidentifier" { let destinationvc = segue.destinationviewcontroller leaderbardcontroller destinationvc.matchid = classevent.id } } }
wiki
Comments
Post a Comment