Your RubyMotion AppDelegate needs a @window accessor
I've seen a lot of code for AppDelegate
classes in RubyMotion that looks a lot like this:
class AppDelegate
def application(application, didFinishLaunchingWithOptions:launchOptions)
@window = UIWindow.alloc.initWithFrame(UIScreen.mainScreen.bounds)
@window.rootViewController = UIViewController.new // ...
@window.makeKeyAndVisible
true
end
end
But there's a tiny error in this code. It's small, but it's still there, and it's relatively pervasive too.
What's wrong with it? Take a look at Apple's documentation for UIApplicationDelegate
:
window
If you want to provide a custom window for your app, you must implement the getter method of this property and use it to create and return your custom window.
How to fix it? Simple:
class AppDelegate
attr_reader :window
def application(application, didFinishLaunchingWithOptions:launchOptions)
@window = UIWindow.alloc.initWithFrame(UIScreen.mainScreen.bounds)
@window.rootViewController = UIViewController.new // ...
@window.makeKeyAndVisible
end
end
Is this pedantic? Absolutely! But I was scratching my head trying to use the MRProgress CocoaPod, and it depends on window being implemented.
Written by Brendan Caffrey
Related protips
1 Response
This seems like it's better way to factor the creation and memoization of the window: https://gist.github.com/tpitale/7807091
over 1 year ago
·
Have a fresh tip? Share with Coderwall community!
Post
Post a tip
Best
#Rubymotion
Authors
Related Tags
#rubymotion
Sponsored by #native_company# — Learn More
#native_title#
#native_desc#