ios - Programatically Setting Root View Controller in Swift -



ios - Programatically Setting Root View Controller in Swift -

i'm not sure why trival, swift translation has been slow one. anyways, can't figure out complaining about. trying set root view controller, , complier spits error saying "splash pagecontroller not have fellow member named init"

here's app delegate:

var window: uiwindow? var client_key = c_key() func application(application: uiapplication, didfinishlaunchingwithoptions launchoptions: [nsobject: anyobject]?) -> bool { // override point customization after application launch. window = uiwindow(frame: uiscreen.mainscreen().bounds) var url_string = "xxxx=\(client_key.client_key)" var g_home_url = string.stringwithcontentsofurl(nsurl.urlwithstring(url_string), encoding: nsutf8stringencoding, error: nil) if (g_home_url? != nil){ nsuserdefaults.standarduserdefaults().setobject(g_home_url, forkey: "showurl") } allow documentsdirectory = nssearchpathdirectory.documentationdirectory allow userdomainmask = nssearchpathdomainmask.userdomainmask if allow paths = nssearchpathfordirectoriesindomains(documentsdirectory, userdomainmask, true){ if paths.count > 0{ if allow dirpath = paths[0] as? string { // allow url: nsurl = nsurl.urlwithstring("\(g_home_url)/xxx\(client_key.client_key)") // println(url) var err: nserror? var g_home_url = nsuserdefaults.standarduserdefaults().objectforkey("showurl") string println(g_home_url) var image = uiimage(data: nsdata(contentsofurl: nsurl.urlwithstring("\(g_home_url)xxx=\(client_key.client_key)"))) allow writepath = dirpath.stringbyappendingpathcomponent("splash_page.png") uiimagepngrepresentation(image) } } } //this error shows var rootview: splashviewcontroller = splashviewcontroller() if allow window = window { window.rootviewcontroller = rootview; }

splashviewcontroller

class splashviewcontroller: uiviewcontroller { override func viewdidload() { super.viewdidload() // additional setup after loading view. } override func didreceivememorywarning() { super.didreceivememorywarning() // dispose of resources can recreated. } /* // mark: - navigation // in storyboard-based application, want little preparation before navigation override func prepareforsegue(segue: uistoryboardsegue!, sender: anyobject!) { // new view controller using segue.destinationviewcontroller. // pass selected object new view controller. } */ }

very basic know. normally, in objective-c init nib name , set view controller that. what's main difference in swift? ahead of time, clear.

this line:

var rootview: splashviewcontroller = splashviewcontroller()

...calls splashviewcontroller's init method. have not given splashviewcontroller init method. give one.

what specify nib in init override; example:

override init() { super.init(nibname:"splashviewcontroller", bundle:nil) }

if don't something along lines, view controller won't find nib , you'll end black screen.

note that code net new error message complaining didn't implement init(coder:); you'll have implement it, if throw error if accidentally called:

required init(coder: nscoder) { fatalerror("nscoding not supported") }

ios swift

Comments

Popular posts from this blog

xslt - DocBook 5 to PDF transform failing with error: "fo:flow" is missing child elements. Required content model: marker* -

mediawiki - How do I insert tables inside infoboxes on Wikia pages? -

Local Service User Logged into Windows -