ios - Swift - Delegate not calling method from other class -


i'm trying change label's text in view controller when button pressed. here's how i'm setting delegate:

in firstviewcontroller under import uikit

@objc protocol mydelegate{     optional func makescore() } 

in firstviewcontroller under class firstviewcontroller: uiviewcontroller

var delegate:mydelegate? 

in firstviewcontroller when button pressed

delegate?.makescore!() 

in secondviewcontroller (where makescore() located)

class secondviewcontroller: uiviewcontroller, mydelegate 

the makescore() method in secondviewcontroller

func makescore() {     println("worked") } 

it's not logging when button pressed. i'm pretty sure set delegates , protocols correctly. see missing?

note: firstviewcontroller , secondviewcontroller not connected segues. both in scrollview.

i can see added second view controller programmatically these lines:

let vc6 = storyboard.instantiateviewcontrollerwithidentifier("second") as! secondviewcontroller self.addchildviewcontroller(vc6) self.scrollview.addsubview(vc6.view) 

just add 1 line, reads this:

let vc6 = storyboard.instantiateviewcontrollerwithidentifier("second") as! secondviewcontroller self.delegate = vc6 self.addchildviewcontroller(vc6) self.scrollview.addsubview(vc6.view) 

edit: on side node, i'm sure delegate best approach you're trying do. you'd better off making global reference secondviewcontroller, calling on self.vc6.makescore(). delegates typically used calling objects not contained in view controller


Comments

Popular posts from this blog

c++ - No viable overloaded operator for references a map -

java - Custom OutputStreamAppender not run: LOGBACK: No context given for <MYAPPENDER> -

java - Cannot secure connection using TLS -