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)
Related
I have an iPhone app that works and is getting used. I now want to upgrade this application to a Universal app. Taking that into consideration I've already made changes, like creating another MainWindow.xib for the iPad, which i've gotten to work. I've pretty much got the whole iPhone App working for the iPad. The next step I needed to take was to convert my Events Calendar to be a splitview. As far as I can tell, I'm don't need to change any of the logic in the two controllers I already have (CalendarViewController and CalendarDetailViewController).
That being said, what is the best way to make them work on a splitview? Is it possible to have the splitview use these two controllers (since a splitview has two controllers by default, a TableViewController and a ViewController)? Would I then need to create another appDelegate or something to pass all the right information back to the MainWindow.xib? Or am I going to need to create a new SplitViewController? and if so, how would I then combine all the logic from my two Calendar Controllers?
Any help would be greatly appreciated!!
Assuming you are using StoryBoard: drag a SplitViewController into the iPad StoryBoard. Also be sure your two desired UIViewControllers are in there. Control-click on the SplitViewController and drag over to each UIViewController and select you how want it set.
I know it's a bit late to answer this question but if someone needs...
You donĀ“t need another appDelegate, you just need to check (in appDelegate) whether your device is an iPad, and then set an array of view Controllers with the MasterVC and the DetailVC. Otherwise you will set your rootViewController as you are doing now in the iPhone app.
It would be something similar to that:
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
[...]
YourMasterVC *mvc =
[[YourMasterVC alloc] initWithStyle:UITableViewStylePlain];
UINavigationController *masterNav =
[[UINavigationController alloc] initWithRootViewController:mvc];
YourDetailVC *dvc = [[YourDetailVC alloc] init];
cvc.detailViewController = dvc;
if ([UIDevice currentDevice].userInterfaceIdiom == UIUserInterfaceIdiomPad) {
// On iPad
UINavigationController *detailNav =
[[UINavigationController alloc] initWithRootViewController:dvc];
UISplitViewController *svc = [[UISplitViewController alloc] init];
svc.delegate = wvc;
svc.viewControllers = #[masterNav, detailNav];
self.window.rootViewController = svc;
} else {
// On iPhone
self.window.rootViewController = masterNav;
}
[...]
}
I am quite new in XCode and I am trying to build my first (serious non example application). The last days, I have attended a seminar on XCode and I am trying to follow the exact steps we did there in the examples in order to build me own app.
I am facing the following issue:
When I am trying to run the application I am getting the following error:
Terminating app due to uncaught exception 'NSUnknownKeyException', reason: '[ setValue:forUndefinedKey:]: this class is not key value coding-compliant for the key view.'
I am creating an new project and I insert an new .h, .m and xib file (New File --> Obkective-C Class, Class:ASViewController, Subclass UIViewController and I also check the With XIB for user interface)
I leave my xib file empty! No controls inside.
I go to the ASAppDelegate.m and I am making the connection of this with my xib file in order to run the app with this xib file.
#import "AS_MainViewController.h"
#import "ASAppDelegate.h"
#implementation INGAppDelegate
- (void)dealloc
{
[_window release];
[super dealloc];
}
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
self.window = [[[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]] autorelease];
// Override point for customization after application launch.
AS_MainViewController *MyrootViewController = [[AS_MainViewController alloc]
initWithNibName:#"AS_MainViewController" bundle: [NSBundle mainBundle]];
self.window.rootViewController = MyrootViewController;
self.window.backgroundColor = [UIColor whiteColor];
[self.window makeKeyAndVisible];
return YES;
}
My ASAppDelegate.h is like this:
#import <UIKit/UIKit.h>
#interface ASAppDelegate : UIResponder <UIApplicationDelegate>
#property (strong, nonatomic) UIWindow *window;
#end
finally, I go to the Summary of the application and in the section iPhone / iPod Deployment Info in the Main Interface drop down list I chese the AS_MainViewController
I build and build success, I run it and I am getting this error!
Does anyone have any idea on a possible solution?
Thank you.
Your problem is with this step:
finally, I go to the Summary of the application and in the section
iPhone / iPod Deployment Info in the Main Interface drop down list I
choose the AS_MainViewController
Don't do this. Then it will work.
If you want to run application by choosing an xib in the Main Interface section then I have given an answer over here:
What is the use of Main Interface option in the build settings for iOS application?
Check it out.
Open your Xib file, right click on File's Owner. Remove all the yellow warning flags and then re-run it
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.
Since there seems to be no window settings in UIStoryboard editor,
I want to know how to switch the AppDelegate's window class from UIWindow to its subclass.
What I often do is writing the following codes in application:didFinishLaunchingWithOptions:,
but each time it really makes me dull.
UIViewController* vc = self.window.rootViewController;
self.window = [[MyWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
self.window.rootViewController = vc;
Any ideas?
You are doing the right thing. That is the way to customize your window. Setting it in IB is just as cumbersome, if you think about it.
If you are dulled by the prospect of typing these three lines of code, consider the convenient feature of the Code Snippets Library in Xcode.
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.