cocoa's event prior to applicationDidFinishLaunching - objective-c

I'm trying to load a window's size and other properties on application start. Unfortunately, if i do it on
applicationDidFinishLaunching
or
applicationWillFinishLaunching
... i get an ugly flicker, showing the unmodified window and quickly switching to a modified one. I know how to do this for my non-main windows that run with window controllers (usually i do this in awake from nib event), but how would i do it in an application delegate?
Thank you

You can tell the window to not be visible at launch, which means you can create your window, mess with its frame size and all that, and then show it.

Related

Cocoa: Update views outside NSWindow's content view during live window resizing?

I have a standard NSWindow with a toolbar. One of the toolbar's items is a custom view -- specifically, an NSTextField. (More specifically, it's a timer app -- the timer's controls as well as the digital display are all within the toolbar, with other stuff in the window's content area. The NSTextField is the digital display.)
Ordinarily, I just update the timer every second by changing the 'stringValue' property of the NSTextField, which causes it to update itself. But during a live window resize, even though the code that updates the 'stringValue' property is running (which I have verified with NSLog), the NSTextField doesn't draw itself again until the window resizing is done. Meanwhile, the stuff inside the content area is updating itself just fine.
I've tried all the ways I know to tell the NSTextField to draw itself, but it just refuses to happen until the live resize is done. Any ideas? Obviously it must be possible somehow, as the toolbar gets resized along with the rest of the window -- so you'd think it would be possible to force it to redraw one or more of its subviews as it is moving them around. I'm assuming I can hack this together by subclassing something, but my Cocoa-fu is not yet strong enough to figure out the easiest/most proper way to do so.
Thanks in advance...
EDIT: I kind of figured out a solution -- it's not great but it mostly works for now. It's in my comments below.
Just invoke -[NSWindow displayIfNeeded] after marking the view as needing display. I encountered this problem when implementing the Mac driver for Wine (an open-source project for running Windows software on OS X and other Unix-like OSes).
http://source.winehq.org/source/dlls/winemac.drv/cocoa_window.m?v=wine-1.7.11#L1905
(That's LGPL code, so you want to consider before copying it. But you can learn implementation techniques from it without worry.)

Not loading the window from the MainMenu.xib, instead load another window

This is my first Mac OS-X app, so this might be a stupid question.
In my app basically i have two windows,
The Main window which comes with MainMenu.xib file by default
I created another WindowController with another xib file.
I have created a AppController class which is connected to the MainMenu.xib, what i am trying to do in the awakeFromNib method in the AppController class is load either the main Window or the custom window, but load the Main Menu each time. Is it possible?
I couldn't do it the previous way, if i needed to use the custom window, i would first create the main window and close it immediately.
I tried to get the main window by this, [[NSApplication sharedApplication]mainWindow]; and then closing it. But was unsuccessful.
I dont think i have proper understanding yet with windows, views and controllers of cocoa. i am following aaron hillegass's COCOA Programming for Mac OS X book.
please suggest me some other tutorials so that i can understand this thing clearly.
You need to un-check the windows "Visible at Launch"
Then based on your BOOL value, you need to show the window and make it orderFront.

Can you force a NSWindow to load, i.e. before it is presented onscreen?

I am all in favor of lazy instantiation of objects only once they are needed, especially with heavy ones like NSWindows. Unfortunately though I am using a WebKit view and need a way to preload a page (which can take up to 10) seconds, so I would like to kick off the view hierarchy initialization as soon as the app launches. I am building a task bar application so no windows are visible at startup.
My first instinct is a quick "hide and show" but there must be a better way to force a window to unarchive itself and call its awakeFromNib and windowDidLoad methods?
If you're using an NSWindowController to manage the window, you can call the window controller's -window method to cause it to load the window without showing it. Like so:
// Window is not loaded
[windowController window];
// Window is now loaded but not on screen
[windowController showWindow:nil];
// Window is now visible

What is the event in cocoa for NSWindow that tells that NSWindow is now displayed after first run?

I need to show a sheet dialog soon after the main window has been shown after first run. If I do it in the init or awake from nib , it does not seem to work right (sheet show as window detached from main window if I do it in the init method). I guess I have to show sheet once the parent window has shown. I have an appcontroller class which has a window pointer. So I guess I need to register as a delegate or something with window ? and implement some method to receive that call ?
Thanks,
There is no reliable event, notification, or delegate method call. It is expected that your code is responsible for showing the window, so it should already know when the window is shown.
Are you relying on the Visible at Launch property set in Interface Builder? If so, what you using to load the NIB? Hopefully, a window controller. In that case, you should be calling the -window method to load the NIB and obtain the window. The resulting window reference is what you would pass to the method that begins the sheet.
If not relying on Visible at Launch, what code are you using to show the window? For example, invoking -showWindow: on the window controller? So, put the code to show the sheet right after that.
applicationDidFinishLaunching: is your entry point. It is sent to your app delegate after the app is all set up, but before the user has had a chance to interact with it.

UIViewController - mysteriously slow to load

I'm writing a tab-based universal app where one of the tabs takes considerably much longer to load than the rest (approximately 5s), and it locks down the main thread while doing it.
Now, this specific tab is an image gallery, so it could be expected to take a little while to load and display the images, however, the delay occurs before I instantiate any of my variables... (The image loading is done on a separate thread anyway...)
I create my subviews etc. in the viewDidLoad method, but the delay occurs somewhere after the init method and before the viewDidLoad method.
(The delay is present even if I comment out everything in the viewDidLoad method.)
The View Controller is initialized with a nib containing nothing but a UIScrollView and a UIImagePickerController...
Does anyone know what's being loaded/processed before the viewDidLoad method?
This is a problem with loading UIImagePickerController on the phone while being attached to the xcode harness. This creates a longer than normal delay. Try testing on the device without being connected to the xcode debugger.