Issues with running app from MainWindow nib? - uiview

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.

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.

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]];

In XCode 4.6 how do you create a brand new iOS application combining a tabbed main application with a navigation controller on one of the tabs?

I am trying to add a navigation controller inside a tab bar controller in a brand new non-storyboard (plain old nib) style.
I found this demo which assumes that XCode has a new project template called "Tab Bar Application". It doesn't. Now XCode 4.6 has "New Tabbed Application". Of course, Apple in their great wisdom has decided that I should not have a main window nib (.xib) and should have the tab bar controller and its pages coded for me in the app delegate instead of in a new-user-friendly NIB instantiated tab controller. I guess that's because it's more flexible that way, and you can write code to decide what tabs the user sees and what tabs they don't see. If I turn on Storyboards, then I guess I can do everything visually still.
I am deeply confused by the long and tortured history of XCode version differences, which affect the validity of existing questions on stackoverflow and demos elsewhere on the web, that reference different iOS versions, and different XCode versions, and make assumptions specific to versions of XCode and iOS that now appear to have changed, and which each rely on different choices with respect to the contents of your Main Nib File Base Name being set or not set.
I also find that it seems that pre-storyboard-Nibs and the complexities of combining various UIKit widgets and controllers has been a primary motivation behind the creation of storyboards.
I am working in a real non-storyboard nib-based application that appears to have been created before this change of heart at apple, and I can see that at startup a lot of unecessary views are created automatically by nib-instantiation and then deleted, in order to dynamically hide and show tabs on the tab bar controller. This appears to have been thought about a great deal at Apple, and they've changed the recommended practices implicitly by changing the way new applications are generated in XCode. I'm not questioning their wisdom, in fact I appreciate the change, but it's left me lost and confused.
Anyways, I'm just trying to put a navigation controller inside a tab in the main tab bar, and I already have an application that must have been started back when XCode used to generate a main window and generate a "Tab Bar Application" with a top level view that is a tabbed view, and the tab bar controller is nib instantiated. The demo above assumes as much.
Apple apparently famously never has provided a demo of this obvious combination of tab bar plus navigation controller. Or so I'm told. And the Apple Human Interface Guidelines apparently state (or used to state?) that it's better to put a navigation controller inside a tab bar than vice versa, and my question should be understood as wishing to comply with the HIG however possible, so I believe I'm asking about the recommended combination, not the discouraged combination.
Here's what I've tried so far:
Tried to follow this blog post, from circa 2009, which assumes things true about older versions of XCode that are no longer true.
Starting with a new tabbed application which XCode generated for me, with storyboards turned OFF, I have a root app delegate .m file that it generated for me that apparently creates at app-startup time, a Tab Bar Controller object completely in code, and which has no Main Window nib. The following code is entirely written by Apple, and I am wondering where (as a relatively new Cocoa developer) I'm supposed to break into this and place my new stuff, if I wanted to change one of the tabs to hav a nav bar and its associated UINavigationViewController:
-- This marker helps stackoverflow's busted markdown system not be confused --
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
// Override point for customization after application launch.
UIViewController *viewController1, *viewController2;
if ([[UIDevice currentDevice] userInterfaceIdiom] == UIUserInterfaceIdiomPhone) {
viewController1 = [[RPDAFirstViewController alloc] initWithNibName:#"RPDAFirstViewController_iPhone" bundle:nil];
viewController2 = [[RPDASecondViewController alloc] initWithNibName:#"RPDASecondViewController_iPhone" bundle:nil];
} else {
viewController1 = [[RPDAFirstViewController alloc] initWithNibName:#"RPDAFirstViewController_iPad" bundle:nil];
viewController2 = [[RPDASecondViewController alloc] initWithNibName:#"RPDASecondViewController_iPad" bundle:nil];
}
self.tabBarController = [[UITabBarController alloc] init];
self.tabBarController.viewControllers = #[viewController1, viewController2];
self.window.rootViewController = self.tabBarController;
[self.window makeKeyAndVisible];
return YES;
}
It now appears that what used to be possible without writing code (according to that 2009 example on the blog I linked to) is now done purely in code. I have read about 500 pages of "Programming iOS 5", worked for a few hundred hours on my first app, and tried a lot of demo applications but I'm still a relatively unseasoned Cocoa/iOS developer, and I believe part of my confusion over all this is the "controller and view" pattern, and its rules for combining them, both in code, and in nibs, are not entirely clear to me.
--
Update: You can has teh codez! In the interest of helping out future XCode-cocoa-iOS noobs like me, I have made a complete demo app and posted it on github here.
Screenshot:
I was as confused as you were when I did the same thing, but once you understand the structure you will find out that it is quite simple.
Basically, You want to create a UINavigationController with the RootViewController you want to display first:
[UINavigationController *navController = [[UINavigationController alloc] initWithRootViewController:theViewControllerYouWantToDisplayFirst];
Then just add this controller to the array for your tab buttons.
NSArray *tabs = [[NSArray alloc]
initWithObjects: navController, otherTab, etc];
Then, set your tabs using such array.
UITabBarController *rootController = [[UITabBarController alloc] init];
[rootController setViewControllers:tabs];
and add it to your tab controller to your window:
[self.window setRootViewController:rootController];
And that is it. I took me some time to realize the way things are structured. The Tab View controller just holds a bunch of ViewControllers, you just need to make one of those view controllers your NavigationController.
If you don't mind starting a new app to get the basics going, try this:
Create a Tabbed Application (or whatever it's called nowadays):
Then select the view you want to have embedded in a NavigationController.
Then go to Editor -> Embed -> in NavigationController like shown below:
Your result will look like this:
Cheers!
As explained in the first two answers (both correct), I add another method to come back to the original "Tabbed Application" template (maybe version 3 of XCode? I don't remember).
In this template you'll have a main xib file with, inside, your TabBarController.
You must start from the Empty Application template, then go through this steps:
Add a new file, User Interface, Application Xib. In this tutorial I'll assume you will name it "Application.xib"
Go to your AppDelegate.h file and change this line:
#property (strong, nonatomic) UIWindow *window;
adding IBOutlet:
#property (strong, nonatomic) IBOutlet UIWindow *window;
Go inside AppDelegate.m and change your applicationDidFinishLaunching method with this
:
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
// delete all and leave only the return
return YES;
}
Go inside Application.xib, select "App Delegate" from the Objects Menu, and then in the identity inspector change the Class --> write AppDelegate (or your AppDelegate.h class name)
Always in Application.xib, right click again on App Delegate Object, you will see a "window" Outlet --> link it to the Window object in the Object inspector on the left
Now, come back to the project, go in supporting files, main.m and change the return line like this:
:
return UIApplicationMain(argc, argv, nil, nil);
then, go inside the main .plist file and add a key: right click, add, key, "Main Nib File Base Name", Type String, Value "Application" (without quotes, without .xib extension)
Ok, now you have an empty "old style" nib application. Now you can go again inside Application.xib, drag your TabBar and link it as the Window "root view controller" (right click on the Window, link the root view controller property).
Then, inside the tab bar, you can drag ViewControllers, Navigation controllers, ecc...
If you need other details or images write me
EDIT:
I uploaded a sample project if you want to look: http://www.lombax.it/documents/ManualTab.zip
Screenshot:
I had a working application that I wanted to place under one "leg" of a tabbed application. I wanted to develop other portions of the "bigger app" under the other tabs. I didn't want to use storyboards. That removed a good deal of the solutions I found. Most of the remaining solutions were developed using older versions of Xcode and they simply wouldn't work with the version of Xcode I downloaded in Feb of 2013.
I tried creating my own tabbed application - (starting with an "Empty Application") as some of the developers on this thread had used. I felt like I was getting close, but I simply couldn't get it to work.
There is an excellent tutorial on using a "Tabbed Application with a Navigation Controller" by Vishal Kurup.
With a minor modification (listed below) by following the video I was able to slip my existing application under the default "Tabbed Application" created by Xcode.
Create a TabBar Controller with a Navigation Controller + Detail View in Xcode 4.3
can be found at
http://www.youtube.com/watch?v=UMpNbCs4mr4
the only real change I had to make from the default "Tabbed Application" was in the AppDelegate.m:
the following code supplied by the selecting "Tabbed Application" wouldn't serve my purpose
self.tabBarController.viewControllers = #[viewController1, viewController2];
this did
self.tabBarController.viewControllers = [NSArray arrayWithObjects:navigation ,
viewController1 ,viewController2, viewController3, viewController4, nil];
A big thank you goes out to Mr Vishal Kurup.
He has made a number of quality videos on iOS development.

How to show up a Window?

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 .

After copying xib and ViewController to a new project my app doesn't draw and crashes on touch events

I have copied some files from a very small (and working) project to a bigger Xcode project.
In particular I have copied a xib file (with just one UIView subclass element), the UIView subclass, and ViewController.
The smaller project simply draws a color background and draws circles as long as the user touches the screen.
I have adapted the code of the bigger project so that at the beginning it loads the xib file. I have added this to the AppDelegate so that it loads the new xib instead of the old one.
(see edit #1 for more details)
Even if drawRect is called (I've tested adding NSLog) nothing is shown[*]. Moreover if I click on the screen of the simulated iPhone the app crashes.
int retVal = UIApplicationMain(argc, argv, nil, nil);
Program received signal EXC_BAD_ACCESS
I am not sure where the problem lies so please let me what I can post.
I have Xcode 4 and I am working with iOS 5.
Thanks for your help. I hope this question is not too naive.
EDIT #1:
This is my xib with a list of classes. I am trying to edit the source code for a Jabber Client that I have found here inserting my own views.
I cannot post image but this is the link
http://i.stack.imgur.com/gDsNb.png
The class CircleDrawer is handling touches and drawing circles.
The class MTViewController is sending a test message.
The class JabberClientAppDelegate (basically unchanged from the downloaded code), connects to the server and authenticates the user. What I have changed is this method:
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
// Override point for customization after application launch.
self.viewController = [[MTViewController alloc] initWithNibName:#"MTViewController" bundle:nil];
self.window.rootViewController = self.viewController;
[self.window makeKeyAndVisible];
return YES;
/*
self.window.rootViewController = self.viewController;
[self.window makeKeyAndVisible];
return YES;*/
}
EDIT #2:
I am starting from scratch.
I am trying to rebuild the app but I get a crash. I have started another discussion since it is not directly relevant to this problem.
EXC_BAD_ACCESS right after touchesBegan
[*]: if I simulate pressing the home button for an instant I can see the background color (then of course I don't see anything else because the simulator returns to the springboard).
Check your MainWindow.xib.
Add appDelegate object below your window (in xib).
Set your class property for appDelegate object to your own appdelegate class.
Then your window object should be connected to appdelegate object's window property.
Now in codebase create object of your viewController class and add subview to window.
Hope this steps will give you some idea about code.
I guess you must have already followed all these steps.

Resources