How to show up a Window? - ios

I am learning iPhone development and in my application I have some view but I should use a window, so I want to call a window in an IBaction how can I call a window? I try to use the example with AppDelegate you can see my code :
- (IBAction)start:(id)sender {
self.window = [[[Game1ViewController alloc] initWithFrame:[[UIScreen mainScreen] bounds]] autorelease];
[self.window makeKeyAndVisible];
}
Game1ViewController is type UIWindow.
Best Regards

I believe your app only gets one window. On top of this you place different views. These can be anything that subclasses UIView. These can be controlled by a UIViewController. Usually there is some sort of design style that dictates how the app is structured, between UINavigationController, UITabController, Master/detail.
If you open Xcode and start with one of their templates such as master/detail you can see the transitions between views and how to make one appear/disappear and the interaction between view and view controller .

Related

Mixare iOS call from ViewController

I have iOS 6 app and I'd like to add one more ViewController (storyboard) in which it would be augmented reality. Now, I'm using Mixare, and I could start AR, but cannot exit the view.
I used this tutorial for implementation Mixare as library into my project.
I think that problem is that I'm calling MixareAppDelegate
MixareAppDelegate *delegate = [[MixareAppDelegate alloc] init];
[delegate runApplication];
that uses self.window.rootViewController
self.window.rootViewController = augViewController;
After that, I can close view, but app freezes. Is there anywhere tutorial how to call Mixare as one view in storyboard with navigation?
Is there easy way to call MixareAppDelegate which is a ViewController as viewController not as element in window.rootViewController?
You can only interact with one window at a time.
When you have added the MixareAppDelegate's window then previous window get invisible for further interaction. You have to visible previous window again.
try:
[window makeKeyAndVisible];
it will solve all of your issues.

Choose appropriate level for UIWindow to enable interaction with controllers behind it

I have created a UIWindow to show a menu floating over all controllers globally. I want to set the level such that window is always visible plus user can interact with controllers behind it. Window contains a controller which will expand/contract on user tap. See the pictures below:
Currently, I have tried following approach:
UIWindow *statusWindow = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
statusWindow.windowLevel = UIWindowLevelAlert; //Have tried all three
statusWindow.hidden = NO;
[statusWindow addSubview:_gmDemo.view];//my controller's view
[statusWindow bringSubviewToFront:_gmDemo.view];
This code blocks my interaction with controllers behind it. Moreover, when I set it to UIWindowLevelNormal - 1, window is hidden but I can interact with other controllers.
Please tell me correct way to achieve my goal. Thanks.
Note: I have already read this post.
Found solution myself. Problem was UIWindow's frame as well as level. First I set level to UIWindowLevelNormal. Secondly, I have handled window's frame dynamically on menu's button tap. When menu need to be expand/contract, I appropriately increase/decrease size of UIWindow on delegate's call. That's it.

Adding subview and then keep it visible on top across app

Background and Aim:
In my existing app, I'm trying to provide voice messaging feature to user. The idea is to optionally provide universal access of voice messaging from anywhere in the app to the user (inspired by facebook messages). I have had partial success so far in displaying my mini message dashboard and tap on which opens customized message (popover) view on both iPhone & iPad.
I added my mini dashboard subview on application keywindow and hence it's visible across (top of) all the views when navigating within the app.
[application.keyWindow addSubview:self.messageDashBoardVC.view];
This made it appear automatically (out of the box) on top of even the modal dialogs (mostly) in app presented like this..
[self presentViewController:modelVC animated:YES completion:nil]
Specific PROBLEM statement:
However..
On iPad when a view controller is presented modally with
modalPresentationStyle = UIModalPresentationFormSheet
or UIModalPresentationPageSheet
the mini dashboard hides behind the modal dialog (sheet). HOWEVER, I want user to access voice feature (mini dashboard & popover views) when working on these sheets.
My existing app uses a lot of such modal dialogs (sheets).
General Problem statement:
Is there any reusable component/source code available that does same thing because I think the orientation handling will also be a tricky/quite a work with my approach? Any other problem that you envisage with my approach?
I found some success to specific PROBLEM statement above:-
The modal view is presented (added) to the same window so I simply brought my mini dashboard view in front like this..
UIWindow *appDelegateWindow = [[[UIApplication sharedApplication] delegate] window];
UIView *miniView = (UIView *)[appDelegateWindow viewWithTag:12221]; // 12221 is tag of mini dashboard view.
[appDelegateWindow bringSubviewToFront:miniView];
However, I'm still looking forward to your expert opinion about my approach and open for alternative approach considering orientation and other potential challenges I might get with this approach.
Next up - I am working on bringing my custom popover view in front of modal sheet. As of now, tap on mini view opens the message popover but behind the modal sheet.
self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
MALoginViewController *login=[[MALoginViewController alloc]initWithNibName:#"MALoginViewController" bundle:nil];
MANowPlayingViewController *nav=[[MANavigationController alloc]initWithRootViewController:home];
[self.window setRootViewController:nav];
self.window.backgroundColor = [UIColor whiteColor];
[self.window makeKeyAndVisible];
here MANowPlayingViewController is class of UINavigationController..so you have to create separate class for UINavigationController...then set that into Window RootviewController..
whatever you give in that UINavigationController class will display all pages in your app..you can handle your all common codes inside this class..For example if you add UIButton on that NavigationBar ,it will display in all classes...
thanks..

Linking ViewController to my code?

I created an Empty Application for the iOS and added a ViewController in which gives the following error while
Application windows are expected to have a root view controller at the end of application launch
None of the other google searches seem to help. Thanks in advance.
If using storyboards, delete everything from didFinishLoading in the AddDelegate (except return yes;). Then in the build settings set default storyboard to your storyboard. Add a view controller to your storyboard, make sure it has the white arrow on the side pointing to it. That should be it.
Creating a view controller subclass and nib is not sufficient. You must actually instantiate your view controller in the app delegate's application:didFinishLaunchingWithOptions: method. You'll probably want to use the initWithNibName:bundle: method to do so, and assign the resulting VC to the rootViewController property of the window created by the app delegate.
All you may need to do if you are using storyboards is add one to the project and configure from there.
Place the following code within application:didFinishLaunchingWithOptions:
self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];

Issues with running app from MainWindow nib?

I had the entire app (it consists of one view) set up and ran from a View in the ViewController object of the MainWindow nib, INSTEAD of actually having the view ran from the actual ViewController nib.
The app runs flawlessly, however I have two warnings. I learned that these warnings are caused by me running everything from the MainWindow nib rather than a ViewController.
Are there any issues with running an app from the MainWindow rather than an actual ViewController? The app is text based and involves constantly updating UILabels. You can find it here if you'd like to take a look at what I'm talking about.
Right now having it set up this way causes no issues... however I am planning on expanding the app. I tried copy and pasting my Scroll View to the actual view controller nib, but when I did I just had a grey screen. Can I leave the app as it is?
But what is there in your MainWindow.xib file? If you just want to have window object, go to your applicationDidFinishLaunching method and create a window object.
- (void)applicationDidFinishLaunching:(UIApplication *)application{
UIWindow *appWindow = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
self.window = appWindow;
[appWindow release];
}
Or you could have select the option Window-Based application while creating a new project.

Resources