ios - Swift 3.0 Delegate Protocol doesn't work -
i have made delegate protocol within 2 view controllers. delegate method doesn't call on code snippet. reason that. couldn't find out issue kindly post suggestions relive issue.
main view controller
class viewcontroller: uiviewcontroller, testdelegatemethod { override func viewdidload() { super.viewdidload() let vw = testviewcontroller() vw.delegatetest = self let push = self.storyboard?.instantiateviewcontroller(withidentifier: "testviewcontroller") self.navigationcontroller?.pushviewcontroller(push!, animated: true) } func testmethod(value:string) { print("hai", value) } }
sub view controller
protocol testdelegatemethod { func testmethod(value:string) } class testviewcontroller: uiviewcontroller { var delegatetest : testdelegatemethod? override func viewdidload() { super.viewdidload() } @ibaction func actsubmit(_ sender: any) { delegatetest?.testmethod(value: "hello how you!") } }
update these changes in viewdidload()
method
override func viewdidload() { super.viewdidload() if let push = self.storyboard?.instantiateviewcontroller(withidentifier: "testviewcontroller") as? selectionscreen { push.delegatetest = self } }
wiki
Comments
Post a Comment