Stop using Interface Builder - iphone

When coding iPhone applications, I've never used Interface Builder myself; thought it was too complicated and useless.
Problem is, I decided to pick up an abandoned opensourced project on GitHub which uses Interface Builder, and I can't seem to stop using it.
It seemed to be that I should start from scratch on programatically coding views, so I went to the application's Info.plist and deleted the NSMainXIBFile (or something like that) related keys.
Once I did so, the application launches, and a message is printed by the console: Applications are expected to have a root view controller at the end of application launch.
I can't seem to find the issue here; I have done:
NSArray *controllers = [NSArray arrayWithObjects:controller1, controller2, nil];
UITabBarController *tabBarController = [[UITabBarController alloc] init];
[tabBarController setViewControllers:controllers];
[window addSubview:tabBarController.view];
[window makeKeyAndVisible];
Am I skipping some key step on stopping using Interface Builder or is my error at the code itself?

You shouldn't add the tab bar controller's view to the window as a subview. You should set it as the window's root view controller instead:
window.rootViewController = tabBarController;

You need to properly assign the property window.rootViewController, not add the tab bar controller as a subview.
self.window.rootViewController = tabBarController;

Try
#synthesize window = _window;
_window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
[self.window makeKeyAndVisible];
And then add a subview to the window.

Related

How should I replace the rootViewController of my main window?

I'm building an app that does a ton of setup when the app loads. As such, I have a loading view that displays some information to the user while the setup takes place...
MyLoadingViewController *loadingViewController = [[MyLoadingViewController alloc] init];
self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
self.window.rootViewController = loadingViewController;
[self.window makeKeyAndVisible];
.
.
//Setup code happens here
.
.
MyHomeViewController *homeViewController = [[MyHomeViewController alloc] init];
self.window.rootViewController = homeViewController;
When the setup code completes, I want to transition into my home screen. Is setting the rootVewController to the new home view controller the proper way to do that kind of a transition?
Thanks so much for your wisdom!
Yes, that's an ok way to do it -- you won't have any animation, but it should work fine. loadingViewController will be deallocated after you switch the root view controllers -- if that's not what you want, then you should create a property to point to it.
I sometimes cheat a little by having the ViewController that does all the loading display an image that is the exact same as the default.png on screen while it loads, then animate it out once complete.
For example in my LoginViewController I firstly display the default image in viewDidLoad, contact the server for auto login and then fade out the image once the app logins. The user never notices as he just sees the default image fade out once the app is ready.

App wont start using testflight on iOS6

I have an application that I want to test it on iOS device. The application uses NIB files and no story board.
Target framework is set to - 5.1
Device - Universal.
I have created the IPA file and uploaded to TestFlightApp.
I have downloaded and installed the application on my iPad. Weird thing is when I tap on the icon a black screen shows and nothing else happens.
I have done the following settings.
Main Interface - SSDMainViewController
Main Storyboard - Not set as I don't have any storyboard in the applicaion.
It is not the problem of IOS versions as other apps are working fine.
EDIT : When I double click the iPad button I saw that the application
is not crashing. It is running in the background.
EDIT 2 : More information on the question.
Well I have taken a view based application and it has all NIBs no storyboard. It was initially an iPhone application targeting the IOS 5.1 but then I have changed the value from the project drop down to UNIVERSAL. But that I think is no problem because when I installed it in my iPad it showed me nothing. Also it showed black screen with the iPhone frame and then nothing. The application is still live in the thread.
What bothers me is that I have done this in the AppDelegate :
I have set the
self.mainViewController = [[SSDMainViewController alloc] initwithnibname:#"SSDMainViewController" bundle:nil];
And then I have set the navigation controller and then pushed the view to it.
I FOUND SOME MORE INFORMATION
In the console it says.
The application is expected to have its root view set at the end of application start.
MY APP DELEGATE
ftipValue=0.25;
cardtype = #"American Express";
[cardtype retain];
[self CallFunctionForLogout];
self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
// Create an instance of YourViewController
//SSDMainViewController *yourViewController = [[SSDMainViewController alloc] init];
self.mainViewController = [[[SSDMainViewController alloc] initWithNibName:#"SSDMainViewController" bundle:nil] autorelease];
// Create an instance of a UINavigationController
// its stack contains only yourViewController
UINavigationController *navController = [[UINavigationController alloc]
initWithRootViewController:self.mainViewController];
navController.navigationBarHidden = YES;
// Place navigation controller's view in the window hierarchy
[[self window] setRootViewController:navController];
[self.window makeKeyAndVisible];
return YES;
Please use two xib file, universal app we want two xib (nib)
one for iPhone - ViewController_iPhone
second for for iPad - ViewController_iPad
Add following code to your AppDelegate.m file.
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
self.window = [[[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]] autorelease];
// Override point for customization after application launch.
if ([[UIDevice currentDevice] userInterfaceIdiom] == UIUserInterfaceIdiomPhone)
{
self.viewController = [[[ViewController alloc] initWithNibName:#"ViewController_iPhone" bundle:nil] autorelease];
}
else {
self.viewController = [[[ViewController alloc] initWithNibName:#"ViewController_iPad" bundle:nil] autorelease];
}
self.window.rootViewController = self.viewController;
[self.window makeKeyAndVisible];
return YES;
}
I have done this and it's work fine for me.
That error means that you're not setting up your application correctly.
You say you've set SSDMainController as the main interface file - is this both for iPhone and iPad? There are two sets of entries in that section of the summary tab for universal apps.
I would expect a different xib file to be specified for the iPad, since a different sized view and different layout would be in use.
You have either not set the iPad xib, so the app can't set up a window with root view controller, or you haven't set up a valid iPad xib, so it isn't loading at all, with the same results.
If you just want the app to run in the mini-iPhone window with the 2x button, leave it as an iPhone only app.
If you are getting "The application is expected to have its root view set at the end of application start." there are a number of possibilities. Clearly, that is the problem, since you have a black screen with nothing in it...
Check out this SO question: Application windows are expected to have a root view controller at the end of application launch warning Rob Mayoff has a good description of what should be happening when your application initializes.
Also, linked to in the above post, is this post wherein there are an additional 35 answers with various scenarios of what could be happening.
Beyond browsing through those links, you will need to post up additional code and/or descriptions of how your nibs are wired up for anyone to help you--as evidenced by the myriad ways it is possible to cripple the initialization sequence.

UINavigationController in iOS 5.1

I am new in Objective-C and iOS. I followed UINavigationController.
In the first 2:30min off the video, He uses AppDelegate interface and implementation and There are some codes provided there which I don't have in my application.
In the interface he has:
#Class ViewController;
...
#property(strong, nonatomic) ViewController *viewController;
which I don't have.
And in the implementation of AppDelegate, before he start to define navigationViewController, he has some lines of codes in didFinishLaunchingWithOption like:
self.windows = [[UIWindows alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
self.viewController = [[ViewController alloc] initWithNibName:#"ViewController" bundle:nil];
self.windows.rootViewController = self.viewController;
[self.windows makeKeyAndVisible]
return YES;
I got warning on self.viewController.
but I just have:
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
// Override point for customization after application launch.
return YES;
}
To nix the NavigationViewController, he adds this line:
UINavigationController *navigationViewController = [[UINavigationController alloc] initWithRootViewController:self.viewController
self.windows.rootViewController = navigationViewController;
When I added this code I faced an error (warning on self.viewController at the end).
When I run the project, it just show the navigation at the top, but the TableView that I created before, is disappeared.
Can you help me how can I fix this problem? My simulator is version 5.1.
I am assuming since this is Part 12 of his youtube series, he is building off previous code.
Regardless, there are many ways to add the rootViewController to the window. (programmatically, via Storyboards, etc.)
The simplest way to get a project setup which would match his tutorial would be:
Create a new "Single View" Project in Xcode and DO NOT enable Storyboards.
This will create a project with an AppDelegate, ViewController class and ViewController xib.
(If you selected Universal app you will have 2 xib files)
Open up the AppDelegate for this newly created project and it should very close to his screencast...
Good luck!
(note this was verified with XCode 4.3.3)

Problem with getting a modalViewController to appear

I've been fighting with this for hours. I've searched around everywhere and just can't seem to find the solution to my problem. I'm pretty sure I'm just lacking some key concepts here.
My AppDelegate (didFinishLaunching) basically sets up my window and invokes RootViewController:
// create our window
UIWindow *window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
[window setBackgroundColor:[UIColor blackColor]];
// create our rootviewcontroller
RootViewController *controller = [[RootViewController alloc] init];
// add our rootviewcontroller's view to our window
[window addSubview:controller.view];
// controller is now owned by window's view
[controller release];
// show us to the world
[window makeKeyAndVisible];
When I add controller.view as window's subview, my understanding is that RootVC's loadView will automatically get called.
In RootVC loadView, I create a tabBarController, each tab having a navigationController and it's own viewController. All that is working fine.
In RootVC viewDidLoad, I'm checking to see if this is the first time a user is running this app, and if so, I want to throw up a modal welcome screen. This is the part I'm having trouble with.
I'd like to keep as much code out of the RootVC's viewDidLoad method, and ideally would be able to accomplish what I want with this:
WelcomeViewController *welcome = [[WelcomeViewController alloc] init];
[self presentModalViewController:welcome animated:true];
[welcome release];
Obviously this isn't working. WelcomeVC's loadView hasn't been run yet because I haven't explicitly set it's view property. I've played around with a bunch of different solutions (welcome.view - [[UIView....], using WelcomeVC's init method to set self.view) but I just can't seem to get that modal to pop up.
How should I accomplish what I'm looking for? What are the best practices, and what's the best solution to keep my code tight and tidy?
I'm stuck, so hopefully your solution will allow me to continue developing my app!
Although the problem is not so simple, the solution is. You have to wait until the main view appears. So check the condition and present your modal view in viewDidAppear method, not in viewDidLoad method.

How to present a modal view controller on the iphone without a "current" view controller?

I'm trying to open the email view controller (MFMailComposeViewController), and everything I read suggests using presentModalViewController:animated:, which seems to need to be sent to a UIViewController.
For example, in the documentation, it says:
Call the presentModalViewController:animated: method of the current view controller, passing in the view controller you want to present modally.
But I don't have a "current view controller"! My app is otherwise entirely OpenGL, and my setup code looks like:
self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
self.view = [[IPhoneView alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
[window addSubview: self.view];
[window makeKeyAndVisible];
and I set up the OpenGL context in the IPhoneView class.
I've found a number of questions asking how to get a UIViewController from a UIView, and the consensus seems to be: don't. So how can I open the email view controller with that nifty sliding animation?
You can always do your own sliding animation of a view and just pass MFMailComposeViewController to it: Hidden Drawer example
See a similar sliding code here as well: How can I present a UIView from the bottom of the screen like a UIActionSheet?