ios - presentViewController gives Error -
this first question here might not in best format.
in app want show next screen, 1 working fine when alone, there should no problem here. using following code make transition
let dataviewcontroller = self.storyboard?.instantiateviewcontrollerwithidentifier("data") self.presentviewcontroller(dataviewcontroller, animated: true, completion: nil)
on second line self.presentviewcontroller
error message:
cannot convert expression's type '(anyobject?, animated: booleanliteralconvertible, completion: nilliteralconvertible)' type 'booleanliteralconvertible'
the answer found, 1 having same error, function presentviewcontroller
, not presentedviewcontroller
. have admit had problem. after fixing error in code error message did not disappear. show me right direction search or got answer.
you need specify expected type instantiateviewcontrollerwithidentifier
use following line when getting view controller:
let dataviewcontroller = self.storyboard?.instantiateviewcontrollerwithidentifier("data") uiviewcontroller?
the 'as'
keyword informs compiler of real type expect in return (aka. casting).
instantiateviewcontrollerwithidentifier
returns object of type anyobject
. since didn't specify type anyobject
(equivalent toid
in objc) used.
presentviewcontroller
expects uiviewcontroller
instance , give him anyobject
instead, hence error
Comments
Post a Comment