iPad Landscape Mode - How To Add Two Splash Screen - ios

I have successfully finished my app after months of coding. Now I'm trying to add the initial Splash Screen images to my app. How do i proceed? I have two images: one is the company logo and the other is the app logo (these splash screens are to hide the loading time). I have looked every where for an possible answer, but ended up with no solution. When i name a single pic Default-Landscape.png and run the Ipad App - The image is showing until the main view controller loads up, but I want the first image to be displayed for 1 second and fade out to the second image which will also be displayed for 1 second after which the main view controller appears(the original application page).
I have checked various answers, but none seems to work - Xcode 4 and iPad2 splash screen issue
Setting splash images for portrait and landscape mode - IPad
etc..
Here is my code for the same - AppDelegate.h
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
NSArray *docDir=NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *docPath=[docDir objectAtIndex:0];
databasePath=[docPath stringByAppendingPathComponent:#"something.sqlite"];
//databasePath1=[docPath stringByAppendingPathComponent:#"something.sqlite"];
NSString *bundlePath=[[NSBundle mainBundle]pathForResource:#"something" ofType:#"sqlite"];
NSFileManager *mngr=[NSFileManager defaultManager];
if ([mngr fileExistsAtPath:databasePath]) {
NSLog(#"File Exists");
}
else
{
[mngr copyItemAtPath:bundlePath toPath:databasePath error:NULL];
NSLog(#"File Created");
}
self.window = [[[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]] autorelease];
// Override point for customization after application launch.
self.viewController = [[[ViewController alloc] initWithNibName:#"ViewController" bundle:nil] autorelease];
self.window.rootViewController = self.viewController;
[self.window makeKeyAndVisible];
return YES;
}
How should I proceed now? Should I create a new class like (splashScreen 1 and splashScreen 2) with uiImageView and change the didFinishLaunchingWithOptions method? Any help would be greatly appreciated.
Updated: 30 May 2013
Appdelegate.h
#import <UIKit/UIKit.h>
#import "sqlite3.h"
#import "FBInteract.h"
#import "splashScreen1.h"
sqlite3 *dbHandler;
NSString *databasePath;
#class ViewController;
#interface AppDelegate : UIResponder <UIApplicationDelegate> {
UIWindow *window;
UINavigationController *naviObj;
}
#property (strong, nonatomic) UIWindow *window;
#property (strong, nonatomic) ViewController *viewController;
#property (strong, nonatomic) UINavigationController *naviObj;
#end
Appdelegate.m
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
self.window = [[[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]] autorelease];
splashScreen1 *splashScreen1PageObj=[[splashScreen1 alloc]init];
self.naviObj = [[UINavigationController alloc]initWithRootViewController:splashScreen1PageObj];
self.window.rootViewController = self.naviObj;
[[UIApplication sharedApplication] setStatusBarHidden:YES withAnimation:NO];
[self.window makeKeyAndVisible];
return YES;
}
splashScreen1.h and splashScreen2.h
#import <UIKit/UIKit.h>
#import "splashScreen2.h"
#interface splashScreen1 : UIViewController
{
IBOutlet UIImageView *imgObjSplashImage; // IBOutlet UIImageView *objSplashImage; - in splashScreen2.h
}
-(void)hideSplash;
-(void)navigationToMain;
-(void)showSplash;
#end
splashScreen1.m and splashScreen2.m
- (void)viewDidLoad
{
// Do any additional setup after loading the view from its nib.
[NSTimer scheduledTimerWithTimeInterval:1.2 target:self selector:#selector(showSplash) userInfo:nil repeats:NO];
self.navigationController.navigationBarHidden=YES;
[imgObjSplashImage setAlpha:0]; //objSplashImage instead of imgObjSplashImage in splashScreen2
[super viewDidLoad];
}
-(void)showSplash{
[UIImageView beginAnimations:nil context:NULL];
[UIImageView setAnimationDuration:1.2];
[imgObjSplashImage setAlpha:1]; //objSplashImage instead of imgObjSplashImage in splashScreen2
[UIImageView commitAnimations];
[NSTimer scheduledTimerWithTimeInterval:2.4 target:self selector:#selector(hideSplash) userInfo:nil repeats:NO];
}
-(void)hideSplash{
[UIImageView beginAnimations:nil context:NULL];
[UIImageView setAnimationDuration:1.4];
[imgObjSplashImage setAlpha:0]; //objSplashImage instead of imgObjSplashImage in splashScreen2
[UIImageView commitAnimations];
[NSTimer scheduledTimerWithTimeInterval:1.0 target:self selector:#selector(navigationToMain) userInfo:nil repeats:NO];
}
#pragma mark
#pragma mark - Navigation Coding
-(void)navigationToMain {
//[self dismissModalViewControllerAnimated:YES];
[self dismissViewControllerAnimated:NO completion:Nil];
ViewController *ViewControllerPageObj=[[ViewController alloc]init];
[self.navigationController pushViewController:ViewControllerPageObj animated:NO];
[ViewControllerPageObj release];
//[self presentViewController:ViewControllerPageObj animated:NO completion:Nil];
}
-(void)viewWillAppear:(BOOL)animated {
self.navigationController.navigationBarHidden=YES;
}
The problem is ViewController(main ViewController) is not loading...I'm getting error saying "message sent to deallocated instance" in viewDidLoad part of ViewController.m
RootViewController -> splashScreen1 -> splashScreen2 is working fine(with all the animation fading in and out) but the final ViewController is not loading..

For this you definitely want another VC, lets call it StartViewController. Add there an imageView, block rotation and setTimer:
[NSTimer scheduledTimerWithTimeInterval:2.0 target:self selector:#selector(moveOnAndChangeVC:) userInfo:nil repeats:NO];
and if you develop NavigationControl app you should also change rootVC for example:
+(void)replaceRootVCWithVC:(id)vc {
NSMutableArray *viewControllers = [NSMutableArray arrayWithArray:[[sharedAppDelegate navigationController] viewControllers]];
if(![viewControllers isEmpty])
[viewControllers replaceObjectAtIndex:0 withObject:vc];
else
[viewControllers addObject:vc];
[[sharedAppDelegate navigationController] setViewControllers:viewControllers];
}
EDIT:
You should change in your appDelegate line with initializer:
self.viewController = [[[StartViewController alloc] initWithNibName:#"StartViewController" bundle:nil] autorelease];
This should call your VC as a rootVC.
Then in StartViewController.m you should recognize device (this is a iPad only app, right? not universal) and orientation:
+(NSString*)recognizeDeviceAndOrientation {
NSMutableString * returnString;
if([StartViewController deviceInterfaceOrientation] == UIInterfaceOrientationLandscapeLeft || [StartViewController deviceInterfaceOrientation] == UIInterfaceOrientationLandscapeRight) {
returnString = #"Default-Landscape";
} else {
returnString = #"Default-Portrait";
}
if([UIScreen mainScreen].scale == 2.0)
return [NSString stringWithFormat:#"%#%#",returnString,#"#2x"];;
else
return returnString;
}
+(UIInterfaceOrientation)deviceInterfaceOrientation {
return [[UIApplication sharedApplication] statusBarOrientation];
}
This will return you a string with DefaultScreen name with proper orientation. If you handling only one orientation forget about it.
Then in viewDidLoad you add imageView:
- (void)viewDidLoad {
[super viewDidLoad];
UIImageView *imageView = [[[UIImageView alloc] initWithImage:[StartViewController recognizeDeviceAndOrientation]] autorelease];
[imageView setFrame:self.frame];
[imageView setContentMode:UIViewContentModeScaleToFill];
[self.view addSubview:imageView];
[NSTimer scheduledTimerWithTimeInterval:2.0 target:self selector:#selector(moveOnAndChangeVC:) userInfo:nil repeats:NO];
}
This will call a timer and set imageView.
-(IBACtion)moveOnAndChangeVC:(id)sender {
//if you using navigation app
ViewController *vc = [[[ViewController alloc] initWithNibName:#"ViewController" bundle:nil] autorelease];
[self.navigationController pushViewController:vc animated:NO];
}
This will work. And then if you want to get rid of "back button" just change a rootView Controller like i said in the beginning. Do it in your ViewController class.

Related

iOS App UIView rotating, content is not

I'm currently building an iOS app, and the only supported orientations are landscape left and right. I've specified this in several ways:
-(BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation{
return UIInterfaceOrientationIsLandscape(toInterfaceOrientation); //iOS 5 compatibility.
}
-(NSInteger)supportedInterfaceOrientations:(UIWindow *)window{
return UIInterfaceOrientationMaskLandscape; //iOS 6
}
-(BOOL)shouldAutorotate{
return YES;
}
And I've specified the supported orientations as only the landscape ones in the app's Info.plist. When I run the app on my device (or even in the simulator), I know that the root view is in landscape orientation (switcher is on the long side of the screen, as is notification center), however the content still originates from the top left corner of the screen, as if in portrait mode, not the bottom left or top right, like I want it to be. I have no idea what could be causing the content not to rotate with the parent view, as this code worked on iOS 5, but is not on iOS 6.
EDIT: Here's a screenshot.
EDIT: Here's my main.m:
#import <UIKit/UIKit.h>
int main(int argc, char **argv) {
NSAutoreleasePool *p = [[NSAutoreleasePool alloc] init];
int ret = UIApplicationMain(argc, argv, #"ClockApplication", #"ClockApplication");
[p drain];
return ret;
}
And here's my ClockApplication.mm:
#import "RootViewController.h"
#interface ClockApplication: UIApplication <UIApplicationDelegate> {
UIWindow *_window;
RootViewController *_viewController;
}
#property (nonatomic, retain) UIWindow *window;
#end
#implementation ClockApplication
#synthesize window = _window;
- (void)applicationDidFinishLaunching:(UIApplication *)application {
_window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
_viewController = [[RootViewController alloc] init];
[_window addSubview:_viewController.view];
[_window makeKeyAndVisible];
}
- (void)dealloc {
[_viewController release];
[_window release];
[super dealloc];
}
#end
Try changing your method from this
-(NSInteger)supportedInterfaceOrientations:(UIWindow *)window{
}
to this
-(NSUInteger)supportedInterfaceOrientations{
}
EDIT
Try calling your view inside a navigationcontroller like this:
UIViewController *yourViewController = [[UIViewController alloc] init];
UINavigationController *nc = [[UINavigationController alloc] initWithRootViewController:yourViewController];
nc.navigationBarHidden = YES;
[self.navigationController presentModalViewController:nc animated:NO];
[self.navigationController dismissModalViewControllerAnimated:NO];
EDIT
#import "RootViewController.h"
#interface ClockApplication: UIApplication <UIApplicationDelegate> {
UIWindow *_window;
RootViewController *_viewController;
}
#property (nonatomic, retain) UIWindow *window;
#end
#implementation ClockApplication
#synthesize window = _window;
- (void)applicationDidFinishLaunching:(UIApplication *)application {
_window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
UINavigationController *nc = [[UINavigationController alloc] initWithRootViewController:_viewController];
nc.navigationBarHidden = YES;
_window.rootViewController = nc;
[_window makeKeyAndVisible];
}
- (void)dealloc {
[_viewController release];
[_window release];
[super dealloc];
}
#end
Try to add:
_window.rootViewController = _viewController;
EDIT: Anyway your code looks like using "deprecated" style. I would suggest to set up a new project for iOS6 and use its template. It was working on iOS5 but iOS changes.
Only the rootViewController of your UIWindow will receive rotation events.
[_window setRootViewController:_rootViewController];
Check out the apple technical notes.

Switch between two UIViewControllers programmatically

I have two xib files and for each it's own class which overrides UIViewController class. I have a button in first xib file which should take me to new UIViewController when it's pressed. I have managed to make that transition in different ways:
UIViewController* secondViewController = [[UIViewController alloc] initWithNibName:#"SecondViewControllerName" bundle:[NSBundle mainBundle]];
[self.view addSubview:secondViewController.view];
or
UIViewController* secondViewController = [[UIViewController alloc] initWithNibName:#"SecondViewControllerName" bundle:[NSBundle mainBundle]];
[self.navigationController pushViewController:secondViewController animated:YES];
In second UIViewController xib file I have also one button which should take me back to first UIViewController. But I don't know how to navigate back to first UIViewController.
I tried:
[self.navigationController popViewControllerAnimated:YES];
for second way of navigating to second UIViewController, but I get unrecognized selector sent to instance error.
Many thanks in advance for any kind of help.
[edit #1: Adding source code]
Here's source code of first view controller .m file:
#import "ViewController.h"
#import "SecondViewController.h"
#interface ViewController ()
#end
#implementation ViewController
- (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib.
}
- (void)viewDidUnload
{
[super viewDidUnload];
// Release any retained subviews of the main view.
}
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
return (interfaceOrientation != UIInterfaceOrientationPortraitUpsideDown);
}
- (IBAction)switchToSecondPage:(id)sender
{
SecondViewController *secondViewController = [[SecondViewController alloc] initWithNibName:#"SecondViewController" bundle:nil];
[UIView beginAnimations:#"flipping view" context:nil];
[UIView setAnimationDuration:1];
[UIView setAnimationCurve:UIViewAnimationCurveEaseInOut];
[UIView setAnimationTransition: UIViewAnimationTransitionCurlDown forView:self.view cache:YES];
[self.view addSubview:secondViewController.view];
[UIView commitAnimations];
}
#end
Here's source code of second view controller .m file:
#import "SecondViewController.h"
#interface SecondViewController ()
#end
#implementation SecondViewController
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
if (self) {
// Custom initialization
}
return self;
}
- (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view from its nib.
}
- (void)viewDidUnload
{
[super viewDidUnload];
// Release any retained subviews of the main view.
// e.g. self.myOutlet = nil;
}
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
return (interfaceOrientation == UIInterfaceOrientationPortrait);
}
- (IBAction)switchToFirstPage:(id)sender
{
[UIView beginAnimations:#"flipping view" context:nil];
[UIView setAnimationDuration:1];
[UIView setAnimationCurve:UIViewAnimationCurveEaseIn];
[UIView setAnimationTransition: UIViewAnimationTransitionCurlUp forView:self.view.superview cache:YES];
[self.view removeFromSuperview];
[UIView commitAnimations];
}
#end
Here's my AppDelegate.m file:
#import "AppDelegate.h"
#import "ViewController.h"
#implementation AppDelegate
#synthesize window = _window;
#synthesize viewController = _viewController;
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
// Override point for customization after application launch.
self.viewController = [[ViewController alloc] initWithNibName:#"ViewController" bundle:nil];
self.window.rootViewController = self.viewController;
[self.window makeKeyAndVisible];
return YES;
}
- (void)applicationWillResignActive:(UIApplication *)application
{
}
- (void)applicationDidEnterBackground:(UIApplication *)application
{
}
- (void)applicationWillEnterForeground:(UIApplication *)application
{
}
- (void)applicationDidBecomeActive:(UIApplication *)application
{
}
- (void)applicationWillTerminate:(UIApplication *)application
{
}
#end
Entire project is made as Single View Application and targeted for iOS 5.1 in XCode 4.3. I have found sample project which does the same thing I am having trouble with. Here's URL for that project: http://www.devx.com/wireless/Article/42476/0/page/2
It is just written for earlier iOS version. Is anyone able to see what am I doing wrong, since I am really out of ideas?
PS: With this animations in code, or without - same problem occurs, so animations aren't problem, I've checked that.
[edit #2: Adding error info]
Here's error description. In main method on return line as listed below:
int main(int argc, char *argv[])
{
#autoreleasepool {
return UIApplicationMain(argc, argv, nil, NSStringFromClass([AppDelegate class]));
}
}
I get this error:
Thread 1: EXC_BAD_ACCESS (code=1, address=0xc00000008)
[edit #3: SOLUTION]
I would like to thank #btype for his solution below. I found out why code from edit #2 didn't work. Problem was doing this:
SecondViewController *secondViewController = [[SecondViewController alloc] initWithNibName:#"SecondViewController" bundle:nil];
INSIDE OF IBAction METHOD! Looks like ARC wiped my UIViewController as soon as end of scope was reached and that's why I was getting informations about sending messages to released instance. I made SecondViewController private field in my ViewController class and after that everything worked just fine.
If anyone thinks my explanation is wrong and knows what really bothered me, feel free to answer to this question and correct me.
Edit the code:
in AppDelegate.m
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
// Override point for customization after application launch.
ViewController *viewController = [[ViewController alloc] initWithNibName:#"ViewController" bundle:nil];
UINavigationController *navController = [[UINavigationController alloc] initWithRootViewController:viewController];
self.window.rootViewController = navController;
[self.window makeKeyAndVisible];
return YES;
}
FirstViewController.m
- (IBAction)switchToSecondPage:(id)sender
{
[self.navigationController pushViewController:secondViewController animated:YES];
}
SeconViewController.m
- (IBAction)switchToFirstPage:(id)sender
{
[self.navigationController popToRootViewControllerAnimated:YES];
}
This should help.

Pushing View Controller with Two Nav Controllers

I've got an app where I am pushing a modal view controller. It is working fine, but I am concerned I haven't coded it in the most correct fashion. I have instanstiated two navigation controllers, which seems a bit dodgy to me.
Basically I've created a tab bar controller with 3 tabs, then made one of those tabs / view controllers the root. Later I am (using some home-grown markup on core text) popping a view controller when the user touches a particular word in a paragraph. The pushed view controller has a back button which works fine and the app seems to be OK.
Like I said it all works, but it seems I am coding in circles here. Is this correct?
AppDelegate.h
#import <Foundation/Foundation.h>
#interface AppDelegate : NSObject <UIApplicationDelegate, UITabBarControllerDelegate>
{
UIWindow *window;
UITabBarController *tabBarController;
}
#property (strong, nonatomic) UIWindow *window;
#property (strong, nonatomic) UITabBarController *tabBarController;
#end
From AppDelegate.m
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
ViewController *viewController = [[ViewController alloc] initWithNibName:#"ViewController" bundle:nil];
ViewController2 *viewController2 = [[ViewController2 alloc] initWithNibName:#"ViewController2" bundle:nil];
ViewController3 *viewController3 = [[ViewController3 alloc] initWithNibName:#"ViewController3" bundle:nil];
UINavigationController *nav = [[UINavigationController alloc] initWithRootViewController:viewController];
self.tabBarController = [[UITabBarController alloc] init];
self.tabBarController.viewControllers = [NSArray arrayWithObjects:nav, viewController2, viewController3, nil];
self.tabBarController.delegate = self;
self.window.rootViewController = self.tabBarController;
[self.window makeKeyAndVisible];
return YES;
}
ViewController3.h
#import <UIKit/UIKit.h>
#import "JSCoreTextView.h"
#import "PopupViewController.h"
#class JSTwitterCoreTextView;
#interface ReadingViewController : UIViewController <JSCoreTextViewDelegate>
{
JSTwitterCoreTextView *_textView;
UIScrollView *_scrollView;
}
#end
From ViewController3.m
Here I am instantiating another navigation controller. Is this a good idea?
- (void)textView:(JSCoreTextView *)textView linkTapped:(AHMarkedHyperlink *)link
{
PopupViewController *popupVC = [[PopupViewController alloc] initWithNibName:#"PopupViewController" bundle:nil];
UINavigationController *nav = [[UINavigationController alloc] initWithRootViewController:popupVC];
[nav setModalPresentationStyle:UIModalPresentationFullScreen];
[nav setModalTransitionStyle:UIModalTransitionStyleCoverVertical];
[self presentModalViewController:nav animated:YES];
}
From PopupViewController.m
- (void)viewDidLoad
{
[super viewDidLoad];
[self.navigationItem setRightBarButtonItem:[[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemDone
target:self
action:#selector(done:)]];
}
- (void)done:(id)sender
{
[self.parentViewController dismissModalViewControllerAnimated:YES];
}
It appears the answer is "yes". I was under the impression there is a single Navigation Controller for the app, but it's more like one per tab, depending on if there are going to be further pushes from that tab.

Trying to access UINavigationController from within AppDelegate

Ok, I'm still pretty new to iOS development, so I apologize if this is a silly question.
But, I have an AlertView that I call from the AppDelegate then respond when clicking a button in the alert. I can do a NSLog and see that the methods are getting called. But, it's not pushing the view into the stack. Here's a sample of what I have (I'm sure it's wrong):
This is in the AppDelegate.m:
#import "AppDelegate.h"
#import "ProfileConnection.h"
#implementation AppDelegate
#synthesize window = _window;
#synthesize navController;
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
// Override point for customization after application launch.
return YES;
}
-(void)switchToController:(NSString *)controller animated:(BOOL)animated{
NSLog(#"switching to controller %#", controller);
// maybe we can do a check to see if a subview exists...and then push or pop accordingly.
// switch to the "TableView" view
if( [controller isEqualToString:#"ProfileConnection"]){
NSLog(#"switching to the ProfileConnection view");
ProfileConnection *profile = [[ProfileConnection alloc] initWithNibName:#"ProfileConnection" bundle:nil];
[self.navController pushViewController:profile animated:YES];
}
}
-(void)showConnectionFoundAlert
{
NSString *connectFoundMsg = [[NSString alloc] initWithFormat:#"We found someone we'd think you would like to meet: Tony Davis"];
UIAlertView *connectionFoundAlert = [[UIAlertView alloc] initWithTitle:#"Connection Found" message:connectFoundMsg delegate:self cancelButtonTitle:#"Decline" otherButtonTitles:#"Connect", #"View Profile", #"Save For Later", nil];
[connectionFoundAlert show];
//[connectionFoundAlert release];
}
-(void)alertView:(UIAlertView *)alertView didDismissWithButtonIndex:(NSInteger)buttonIndex
{
NSString *title = [alertView buttonTitleAtIndex:buttonIndex];
NSString *alertString = [[NSString alloc] initWithFormat:#""];
if([title isEqualToString:#"Decline"])
{
alertString = #"Declied";
}
else if([title isEqualToString:#"Connect"])
{
alertString = #"Connected";
}
else if([title isEqualToString:#"View Profile"])
{
//alertString = #"Profile Viewed";
//NSLog(#"View Profile is being called");
[self switchToController:#"ProfileConnection" animated:YES];
//UIViewController *profile = [[UIViewController alloc] initWithNibName:#"ProfileConnection" bundle:nil];
//ProfileConnection *profile = [[ProfileConnection alloc] initWithNibName:#"ProfileConnection" bundle:[NSBundle mainBundle]];
//UINavigationController *nav = [[UINavigationController alloc] init];
//[nav pushViewController:profile animated:NO];
/*UIViewController *profile = [[UIViewController alloc] initWithNibName:#"ProfileConnection" bundle:nil];
UINavigationController *navigation = [[UINavigationController alloc] init];
[navigation pushViewController:profile animated:YES];*/
/*
ProfileConnection *profile = [ProfileConnection alloc];
//UIView *current = self.window;
[self.window addSubview:profile.view];
*/
/*
[window addSubview:view1.view];
[window makeKeyAndVisible];
- (void)goToNextPage {
view2 = [ViewController2 alloc];
UIView *current = self.window;
[self.window addSubview:view2.view];
*/
}
else if ([title isEqualToString:#"Save For Later"])
{
alertString = #"Saved It";
}
UIAlertView *alertStr = [[UIAlertView alloc] initWithTitle:#"" message:alertString delegate:nil cancelButtonTitle:#"OK" otherButtonTitles:nil];
if ([alertString isEqualToString:#""]) {
} else {
[alertStr show];
}
}
#end
This is the AppDelegate.h:
#import <UIKit/UIKit.h>
#import "ProfileConnection.h"
#interface AppDelegate : UIResponder <UIAlertViewDelegate, UIApplicationDelegate, UINavigationControllerDelegate> {
UINavigationController *navController;
}
#property (strong, nonatomic) UIWindow *window;
#property (nonatomic, retain) UINavigationController *navController;
-(void)showConnectionFoundAlert;
-(void)alertView:(UIAlertView *)alertView didDismissWithButtonIndex:(NSInteger)buttonIndex;
-(void)switchToController:(NSString *)controller animated:(BOOL)animated;
#end
I am able to add the view with this, but I lose my navigation controller:
ProfileConnection *profile = [ProfileConnection alloc];
[self.window addSubview:profile.view];
You can see I have tried a few approaches, but I'm confusing myself trying to use the storyboard approach.
Also, the ProfileConnection view is blank with a single label at the moment, if that helps.
You code looks ok [self.navController pushViewController:profile animated:YES]; is how you should do it.
You should make sure that you have added the navigation controller to the window. Perhaps this should already be done by the storyboard, but if not user the rootviewcontroller property of the window (its better than addSubview).
self.window.rootViewContorller = self.navController;
Now do a sanity check to make sure nothing is nil (profile or the navController).
NSLog(#"%# %#",self.navController, profile);
Does any of that help?

UINavigationController based app with FlipSideView with another UINavigationController

I'm trying to develop an app (game) with this architecture:
Main view is a naviagtioncontroller based with navbar hidden
in Main view I need a light info
button to show a options/credits
flipsideview
this flipsideview must have another
navigationcotroller with a right bar
button to a "Done" system button
The problem is that the flipsideview doesn't show the done button and it seems to show the Main navigation controller...
This is the code.
AppDelegate:
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
// Override point for customization after application launch.
self.window.rootViewController = self.navigationController;
[self.window makeKeyAndVisible];
return YES;
}
Main View (loaded from a XIB). Extract only of showInfo:
-(IBAction) showInfo:(id)sender {
FlipSideViewController *controller = [[FlipSideViewController alloc] initWithNibName:#"FlipSideView" bundle:nil];
controller.delegate = self;
controller.title = #"Info";
UINavigationController *navController = [[UINavigationController alloc] initWithRootViewController:controller];
navController.modalTransitionStyle = UIModalTransitionStyleFlipHorizontal;
navController.navigationBar.barStyle = UIBarStyleBlackOpaque;
UIBarButtonItem *doneButton = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonItemStyleDone
target:controller action:#selector(done:)];
navController.navigationItem.rightBarButtonItem = doneButton;
controller.navController = navController;
[self presentModalViewController:navController animated:YES];
[doneButton release];
[controller release];
[navController release];
}
- (void)flipsideViewControllerDidFinish:(FlipSideViewController *)controller {
[self dismissModalViewControllerAnimated:YES];
}
FlipSideView. In the XIB I've only a blank view with outlet linked to the UIViewController view.
#protocol FlipsideViewControllerDelegate;
#interface FlipSideViewController : UIViewController {
id <FlipsideViewControllerDelegate> delegate;
UINavigationController *navController;
}
#property (nonatomic,assign) id <FlipsideViewControllerDelegate> delegate;
#property (nonatomic,retain) UINavigationController *navController;
-(IBAction)done;
#end
#protocol FlipsideViewControllerDelegate
- (void)flipsideViewControllerDidFinish:(FlipSideViewController *)controller;
#end
}
Implementation file...
- (void)viewDidLoad
{
[super viewDidLoad];
self.navController.navigationItem.title = #"Pippo";
}
#pragma mark - User Methods
- (IBAction)done {
[self.delegate flipsideViewControllerDidFinish:self];
}
The result is:
Main View showing without navigation
bar
Click on info button
Flipsideview showing with animation
and navigation bar with title "Info" and not "pippo
and not "Done" button on the right...
Where am I wrong??
Don't you get two navigationBar with navigationItems on FlipsideViewController? I am fighting with this bug now.

Resources