xcode7 without storyboard, display not right [duplicate] - objective-c

This question already has answers here:
iOS 9 Xcode 7 - Application appears with black bars on top and bottom
(17 answers)
Closed 6 years ago.
I am working with xCode7 and I am trying to not use storyboards. I have deleted both the launch screen and the main storyboard properties from info.plist and I have created a xib file that is properly linked to the view controllers. In my app delegate I have written the following code:
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
CGRect screenBounds = [[UIScreen mainScreen] bounds];
UIWindow *window = [[UIWindow alloc] initWithFrame:screenBounds];
ViewController *vc = [[ViewController alloc] init];
[window setRootViewController:vc];
[window makeKeyAndVisible];
[self setWindow:window];
return YES;
}
My xib file looks like this in the editor:
Those buttons are there to show the top and bottom.
In the simulator it looks like this:
Can anyone throw some light into the matter? Thanks, P.

This looks like you should take a look into your Top Bar and Bottom Bar. Make sure is none. I hope this can help you.
[viewController.navigationController setNavigationBarHidden:YES animated:YES];
and
[viewController.navigationController setToolbarHidden:YES animated:YES];
I didn't test it on xcode, maybe there is some errors in my code.
I hope this can help you.

Related

Orientation Issue with iOS 8

I have developed an iPad app for landscape orientation using freeform layout in one of
the ViewControllers.
It is working fine with iOS 7, but When I'm running the app using Xcode 6, the
controls in xib position varies.
I have Tried to modify auto layout check box, but no luck.
Can any one help me to solve this issue.
Thanks in advance
Add the following code in the - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions method:
self.window.rootViewController = self.viewController;
[self.window makeKeyAndVisible];
[self.window setFrame:[[UIScreen mainScreen] bounds]];

Xcode - UIStoryboard black screen

I am using a UIStoryboard. I created my application empty, and then I added a storyboard. The storyboard is set as the main storyboard in the project settings and also as the 'Main Storyboard file base name' in the Info.plist.
My app delegate simply returns YES without any other code.
My main.m includes this line of code:
return UIApplicationMain(argc, argv, nil, NSStringFromClass([ARGAppDelegate class]));
I get this message in the console:
Application windows are expected to have a root view controller at the
end of application launch
My view controller is in the UIStoryboard, as the initial view controller.
Just wondering what I am doing wrong here...
My AppDelegate code:
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
return YES;
}
Thats all the code I have, if you are using a storyboard you do not need to create a window right?
Thanks for the help, appreciated!
Update:
I actually changed my AppDelegate code, still does not make a difference:
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
// Override point for customization after application launch.
self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
UIStoryboard *storyboard = [UIStoryboard storyboardWithName:#"MainStoryboard_iPhone" bundle:[NSBundle mainBundle]];
UIViewController *initViewController = [storyboard instantiateViewControllerWithIdentifier:#"ARGViewControllerID"];
NSLog(#"%#", initViewController); // Returns a valid ARGViewController object
[self.window setRootViewController:initViewController];
[self.window makeKeyAndVisible];
[self.window makeKeyWindow];
return YES;
}
Application windows are expected to have a root view controller at the end of application launch
sounds like you hadn't embedded in a navigation controller at the beginning of your storyboard
When -applicationDidFinishLaunching:withOptions: does not set up a window or storyboard in code, the next place the system looks is in the info.plist for a default XIB or StoryBoard. The 'Default Storyboard' field in your project info is either empty, or pointing at a non-existent .storyboard file. Click your project in the tree then the 'Summary' tab and fill in the field with the name of your storyboard file.
Unable to find solution after digging through forums and questions and playing with the code, I switched to xibs. Been happy with it since 4 hours ago when I made the transition. I hope I never have to see another error-filled and hard-to-use storyboard file again!

Tab Bar disappearing when switching views

I was hoping that you could help me with a small issue.
I have a program that has a tab bar controller with 5 tab bar items. On the main page this tab bar appears and I can switch between the 5 tab bar items with no issues.
On some views I have a button which loads a xib file, some of which are xibs that are selectable from the tab bar. However, whenever I load a view using a button I lose the tab bar - and this is my issue.
My current way of loading between views is as follows:
- (IBAction)newGamePressed
{
NewGameIntro *screen = [[NewGameIntro alloc] initWithNibName:nil bundle:nil];
screen.modalTransitionStyle = UIModalTransitionStyleCoverVertical;
[self presentModalViewController:screen animated:YES];
}
This is probably quite an obvious solution but I am pretty new to Objective-C and searching the forum I couldn't find anything particularly obvious.
Any help that anyone can give would be much appreciated.
Thanks in advance!
PS The way I loaded the TabBarController was as follows (if this helps) in the delegate:
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
[[NSBundle mainBundle] loadNibNamed:#"TabBarController" owner:self options:nil];
[self.window addSubview:rootController.view];
self.window.backgroundColor = [UIColor whiteColor];
[self.window makeKeyAndVisible];
return YES;
}
You are presenting a modal view which will cover the entire window as it is designed to. If your goal is to simply push a new controller onto the stack you will need your tab's root views to be a UINavigationController upon which you will simply push another view using
[self.navigationController pushViewController:...]

UINavigationController — left and right flip animation between pushes and pops when presented via presentViewController

Supposed you've got:
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
// Override point for customization after application launch.
UIViewController *rootViewController = [[UIViewController alloc] init];
rootViewController.view.backgroundColor = [UIColor whiteColor];
[self.window setRootViewController:rootViewController];
[self.window makeKeyAndVisible];
UINavigationController *modal = [[UINavigationController alloc] initWithRootViewController:[[PTFrontViewController alloc] init]];
modal.modalPresentationStyle = UIModalPresentationFormSheet;
[rootViewController presentViewController:modal animated:YES completion:NULL];
return YES;
}
whereas PTFrontViewController and PTBackViewController view controllers have nothing interesting for sake of this example.
How could you push an instance of PTBackViewController from PTFrontViewController animating as in UIViewAnimationTransitionFlipFromLeft or UIViewAnimationTransitionFlipFromRight?
I am already well aware of these three things:
this is not exactly how you should make use of presentViewController
there is a good reason for UINavigationController's default animation
there are several answers how to "customize" UINavigationController's default animation while pushing and poping, but if you try the code for your self you will notice that when a view controller is presented via presentViewController there are drop shadows and background views that won't get animated correctly
So please answer taking these things in mind. Thank you.
First - forget UINavigationController. If you don't need the default animation, just put a UINavigationBar into your controllers. It will get a little easier.
Second - this is a difficult problem, you can't create such an animation only within the modal controller because the background wouldn't be repainted.
Sincerely, the easist solution I see is too forget the modal controller and just add the view controller as a child of your root controller. Then you can control all the animations but you have to write everything by yourself (including the background fading).

applications expected to have a root view controller console

I am getting a message within the console when I run my app that says:
2011-11-16 19:17:41.292 Juice[8674:707] Applications are expected to have a root view controller at the end of application launch
I have heard from others that this has to do with the method didFinishLaunchingWithOptions
If anyone has any suggestions for why I am getting this error, it would be much appreciated.
My code for the method:
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
// Override point for customization after application launch.
[window addSubview:tabBarController.view];
[window makeKeyAndVisible];
[[UIApplication sharedApplication] setStatusBarHidden:NO withAnimation:UIStatusBarAnimationFade];
return YES;
}
You should replace the
[window addSubview:tabBarController.view];
to
[self.window setRootViewController:tabBarController];
Maybe you built your project with 'Empty Application' and forgot to set the rootViewController in your didFinishLaunchingWithOptions (which exists in your AppDelegate.m).
However, if you build your project with 'Single View Application' or some other type, the project will set the rootViewController via xib by default (which might be a MainWindow.xib in your project).
I had the same problem on iOS 5, after adding a storyboard to an "empty" project. It turns out I had to remove all the lines in AppDelegate.m that set values to self.window.
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
//self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
// Override point for customization after application launch.
//self.window.backgroundColor = [UIColor whiteColor];
//[self.window makeKeyAndVisible];
return YES;
}
If you have MainWindow.xib, make sure you set Main Interface in Target's summary to MainWindow.
The way I got this error Applications are expected to have a root view controller at the end of application launch to disappear, was to ensure the loadView method in my root view controller was calling [super loadView]. Hope this helps someone.
Try using self.window instead of window (if your setup has window being synthesized with something like #synthesize window=_window;):
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {    
    // Override point for customization after application launch.
    [self.window addSubview:tabBarController.view];
    [self.window makeKeyAndVisible];
    [[UIApplication sharedApplication] setStatusBarHidden:NO withAnimation:UIStatusBarAnimationFade];
    return YES;
}
2nd possibility:
In your main.m make sure the last argument is the name of the App Delegate. In your case, it looks like it should be:
retVal = UIApplicationMain(argc, argv, nil, #"JuiceAppDelegate");
Solution:
As #marcus13 said in the comments below.. This was fixed was found in this SO answer: Applications are expected to have a root view controller at the end of application launch - by by moving the UIAlertView methods from -(void)viewDidLoad to -(void)viewDidAppear:(BOOL)animated
Another cause:
I was in IB attaching File Owner to a new small ImageView I'd dragged onto the View. I hadn't called it an IBOutlet in the .h file, so when I ctrl-dragged to it, the new Imageview wasn't listed as a possible connection. The only possibility displayed in the little black box was View. I must have clicked, inadvertently. I made a few changes then ran the program and got the Root Controller error. The fix was reconnecting File Owner to the bottom View in the xib - IB screen.
I just ran into this issue while building a new project from scratch. I added a StoryBoard and build my whole interface, but i did not select a template.
When doing it this way, you have to make sure of 3 main things:
Always select your initial controller (TabBarcontroller or NavigationController) as the initial view in your Storyboard.
Change the code in your Appdelegate.m from this
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
// Override point for customization after application launch.
self.window.backgroundColor = [UIColor whiteColor];
[self.window makeKeyAndVisible];
return YES;
}
to this
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
return YES;
}
Check your [ProjectName]-Info.plist file. If there is no key named "Main storyboard file base name", you have to manually add it and set it's value to the name of your storyboard file (without the extension).
After i did all of these steps, my application ran perfectly.
I also had the same problem. All I got was a black screen. Turns out I had inadvertently removed:
[self.window makeKeyAndVisible];
from my code. Hope this helps someone!
I had two outlets assigned to "view" in the storyboard's root view controller. Right-click on "view controller" and make sure there's only one "view".
I also had the same error while developing an app that uses sqlite Database.
I was showing alertView when the db file transfer failed.
This was a mistake since you cannot show any popovers/alertview/actions without any rootViewController set!
I fixed it by ensuring that any function that creates and shows these alerts/popovers/actionsheets are called after
self.window.rootViewController = self.tabBarController;
[self.window makeKeyAndVisible];
[someObject functionthatDisplayAlerts];
I know this post is old but I ran into this today.
It's because I created a UIAlertView in didFinishLaunchingWithOptions.
Assuming then we should not be doing this because I commented it out and the error went away. I removed my comments and the error came back.
The app doesn't crash, I just get that logged error.
I had the same problem with my App. It appeared when I added another view controller to my project and tried to set it as the root view controller in AppDelegate. I tried several solutions, but none of them could fix the problem. Finally I found the cause: I had two localized versions of the MainWindow.xib file (One for german and another for english localization). So I deleted the english file and reconnected the IBOutlets in MainView.xib. This solved the problem.
I'm not sure if this will help anybody else, but if you have used interface builder to create your mainWindow and have done all the linking between the delegate make sure you don't have the following code within application:didFinishLaunching ...
[[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]]
I was having the same error until I removed the above line. Hope that helps!
EDIT: Doing the above now has my viewControllers viewDidAppear method being called twice ?
If you are using Storyboard, but created an empty project, you probably forgot to set the Main storyboard to your *.storyboard file in the Summary tab in your project settings. It helped me to solve this problem.
If you are starting from an empty you have to make this addition to your AppDelegate.m file, to "point" the window to the rootViewController (self.window.rootViewController = [[[ViewControllerName alloc] initWithNibName:#"ViewControllerName" bundle:nil] autorelease];)
Like so:
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
self.window = [[[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]] autorelease];
// Override point for customization after application launch.
self.window.backgroundColor = [UIColor whiteColor];
self.window.rootViewController = [[[ViewControllerName alloc] initWithNibName:#"ViewControllerName" bundle:nil] autorelease];
[self.window makeKeyAndVisible];
return YES;
}