ios - callback on function from other class -
i have customview , and there uitextfield
, , in viewcontroller
, using lot of views. in customview.swift
have uitextfielddelegate
. want actions on callback in viewcontroller
. example : when tap on textfield, delegate executes
func textfielddidbeginediting(textfield: uitextfield) { println("delegate") }
and after want function works viewcontroller ui execute, example:
func textfielddidbeginediting(textfield: uitextfield) { println("delegate") viewcontroller().check() }
but gets nil, want create callback, can advise right way this?
create custom property of type viewcontroller
in customview
class. in viewdidload
function of viewcontroller
, call
thecustomview.viewcontroller = self
(where thecustomview instance - have reference well, otherwise create iboutlet)
then, in textfielddidbeginediting
function can use
self.viewcontroller.check()
Comments
Post a Comment