iOS App UIView rotating, content is not - ios

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.

Related

EXC_BAD_ACCESS when adding UINavigationController in code

I have inherited a large code that keeps crashing during applicationDidFinishLaunchingWithOptions on [self.window makeKeyAndVisible] with EXC_BAD_ACCESS (code=2, address...), so I have no useful information on console. Through elimination I have separated a simple example below that will crash when adding navigationController view onto the baseVC.view. Can anybody please help and explain why is it crashing and how to fix it?
#interface ViewController () <UINavigationControllerDelegate>
#property (nonatomic, strong) UIViewController *baseVC;
#property (nonatomic, strong) UINavigationController *customNC;
#end
#implementation ViewController
- (void)viewDidLoad {
[super viewDidLoad];
self.baseVC = [[UIViewController alloc] init];
CGSize size = self.view.bounds.size;
self.baseVC.view.frame = CGRectMake(0.0, 0.0, size.width, size.height );
[self.view addSubview:self.baseVC.view];
self.customNC = [[UINavigationController alloc] initWithRootViewController:self.baseVC];
[self addChildViewController:self.customNC];
[self.customNC setNavigationBarHidden:YES animated:NO];
self.customNC.delegate = self;
self.customNC.view.frame = self.baseVC.view.frame;
[self.baseVC.view addSubview:self.customNC.view];
}
#end
The actual code is I have is more complex, but the behaviour of this sample is the same. Thank you.
Edit:
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
self.window.rootViewController = [[RootVC alloc] initWithNibName:#"RootVC" bundle:nil];
[self.window makeKeyAndVisible];
return YES;
}
self.customNC = [[UINavigationController alloc] initWithRootViewController:self.baseVC];
[self.baseVC.view addSubview:self.customNC.view];
The problem is in this code lines. So, self.baseVC.view is in self.customNC.view, and vice versa. It causes the crash.
EXC_BAD_ACCESS
This exception occurs when you have problem with memory of the app probably something is already released and you try to use it. To debug this use iOS instruments.
Try to add this line to if you do not have this didFinishLaunchingWithOptions:
[self.window addSubview:[self.navigationController view]];
[self.window makeKeyAndVisible];

iPad Landscape Mode - How To Add Two Splash Screen

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.

AppDelegate and .xib are not implementing properly, but build is successful?

I really don't know how to explain this without pasting all my code, but ill give it a shot. "Assuming" my .hs and .ms are accurate, i have a feeling my .xib is not set correctly, but i cant really paste the code from that. Instead i've zipped the files and uploaded the source code. (if you are brave enough, it's here: http://bit.ly/ZtDkGi ) Im getting a successful build, but my emulator's screen is just black after the app launches.
Essentially, i had to manually add an appDelegate object. i set the class to the appropriate class - but its still not pulling. If someone would be kind enough to help, that would be great.
here's my Test_TableViewAppDelegate.h
#import <UIKit/UIKit.h>
#interface Test_TableViewAppDelegate : NSObject <UIApplicationDelegate>
{
}
#property (nonatomic, retain) IBOutlet UIWindow *window;
#property (nonatomic, retain) IBOutlet UINavigationController *navController;
#end
here's my new Test_TableViewAppDelegate.m
#import "Test_TableViewAppDelegate.h"
#implementation Test_TableViewAppDelegate
#synthesize window=_window;
#synthesize navController=_navController;
- (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];
UIWindow *window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
window.backgroundColor = [UIColor greenColor];
self.window = window;
UIViewController *fvc = [[UIViewController alloc] init];
UIViewController *rootController = [[UIViewController alloc] initWithNibName:#"RootViewController" bundle:nil];
UINavigationController *nc = [[UINavigationController alloc]initWithRootViewController:rootController];
//UINavigationController *nc = [[UINavigationController alloc]initWithRootViewController:fvc];
self.navController = nc;
//[self.window addSubview: nc.view];
//[self.window makeKeyAndVisible];
self.window.rootViewController = self.navController;
[self.window makeKeyAndVisible];
return YES;
}
RootViewController.h
#import <UIKit/UIKit.h>
#interface RootViewController : UITableViewController {
NSMutableArray *petsArray;
}
#end
RootViewController.m
#import "RootViewController.h"
#interface RootViewController ()
#end
#implementation RootViewController
and last but not least, main.m ( i think this might be an issue too)
#import "Test_TableViewAppDelegate.h"
int main(int argc, char *argv[])
{
#autoreleasepool {
return UIApplicationMain(argc, argv, nil, NSStringFromClass([Test_TableViewAppDelegate class]));
}
}
thanks in advance. i'd appreciate it :D
in your delegate Test_TableViewAppDelegate
why you adding views two times to the window?
// you could remove these two lines
[self.window addSubview: nc.view];
[self.window makeKeyAndVisible];
//keep these two lines
self.window.rootViewController = self.navController;
[self.window makeKeyAndVisible];
And this view you are adding to the navigationController it is not initalized with any nib name
UIViewController *fvc = [[UIViewController alloc] init];
initialization should be like this instead in your delegate
RootViewController *rootController = [[RootViewController alloc] initWithNibName:#"RootViewController" bundle:nil];
UINavigationController *nc = [[UINavigationController alloc]initWithRootViewController:rootController];
I believe the reason that you're getting a black screen is that you are not properly allocating and initializing your navigation controller!
Instead, you should try this code:
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions: (NSDictionary *)launchOptions
{
// create the base window
UIWindow *window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
window.backgroundColor = [UIColor greenColor];
self.window = window;
[window release];
// this is the home page from the user's perspective
FirstViewController *fvc = [[FirstViewController alloc] init];
UINavigationController *nc = [[UINavigationController alloc]initWithRootViewController:fvc];
self.navigationController = nc;
[fvc release];
[nc release];
// show them
[self.window addSubview: nc.view];
[self.window makeKeyAndVisible];
return YES;
}
Hope this works!

creating a view controller for universal iOS app

update 0
Hold off on answering this question.
I think I have found part of the problem.
XCode aborted again when I tried to rename the automatically generated .xib files it had created with _ to use ~. Xcode seems to destroy at least one of the .xib files when it aborts, and that file contains the minimal view or window object needed by the app. Although the missing .xib file is gone from the Finder, it still shows in the Navigator.
So now, I am going to leave the _ files alone and try again, but not use the suggestion I got earlier.
update 0
I am having trouble with my xibs having changed the following code as recommended here.
I suspect the problem comes from changing the xib names to using '~' instead of '_' and not being able to revise the corresponding code which refers to the xib names.
The problem could also be that I have the following 4 filenames which could be confusing to Xcode?
BSViewController.h/.m
BSViewController~iPhone.xib
BSViewController~iPad.xib
Original code was.
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
// Override point for customization after application launch.
if ([[UIDevice currentDevice] userInterfaceIdiom] == UIUserInterfaceIdiomPhone) {
self.viewController = [[BSViewController alloc] initWithNibName:#"BSViewController_iPhone" bundle:nil];
} else {
self.viewController = [[BSViewController alloc] initWithNibName:#"BSViewController_iPad" bundle:nil];
}
self.window.rootViewController = self.viewController;
[self.window makeKeyAndVisible];
return YES;
}
Altered code (including extra) is.
#import "BSAppDelegate.h"
#import "BSViewController.h"
#implementation BSAppDelegate
#synthesize window;
#synthesize 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 = [[BSViewController alloc] initWithNibName:#"BSViewController" bundle:nil];
[self.window addSubview:viewController.view];
self.window.rootViewController = self.viewController;
[self.window makeKeyAndVisible];
return YES;
}
BSAppDelegate.h follows.
#import <UIKit/UIKit.h>
#class BSApp;
#class BSViewController;
#interface BSAppDelegate : NSObject <UIApplicationDelegate>{
UIWindow *window;
BSViewController *viewController;
}
#property (retain, nonatomic) IBOutlet UIWindow *window;
#property (retain, nonatomic) IBOutlet BSViewController *viewController;
#end
BSViewController.h follows.
#import <UIKit/UIKit.h>
#interface BSViewController : UIViewController<UIImagePickerControllerDelegate, UINavigationControllerDelegate> {
UIImage *workingImage;
IBOutlet UIImageView *imageView;
}
#property (nonatomic, retain) UIImage *workingImage;
#property (nonatomic, retain) IBOutlet UIImageView *imageView;
+ (BOOL)isCameraDeviceAvailable;
- (IBAction) chooseImage:(id) sender;
- (IBAction) grayscale:(id) sender;
#end
BSViewController.m follows.
#import "BSViewController.h"
#interface BSViewController ()
#end
#implementation BSViewController
#synthesize imageView;
#synthesize workingImage;
+(BOOL)isCameraDeviceAvailable
{
BOOL isCameraAvailable=NO;
if([UIImagePickerController isSourceTypeAvailable:UIImagePickerControllerSourceTypeCamera])
{
if([UIImagePickerController isCameraDeviceAvailable:UIImagePickerControllerCameraDeviceFront] )
isCameraAvailable = YES;
}
return isCameraAvailable;
}
- (IBAction) chooseImage:(id) sender {
[self.view addSubview: self.imageView];
UIImage* testCard = [UIImage imageNamed:#"ipad 7D.JPG"];
CGImageRef num = CGImageCreateWithImageInRect([testCard CGImage],CGRectMake(532, 0, 104, 104));
UIGraphicsBeginImageContext(CGSizeMake( 250,650));
CGContextRef con = UIGraphicsGetCurrentContext();
CGContextDrawImage(con, CGRectMake(0, 0, 13, 13) ,num);
UIImage* im = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
CGImageRelease(num);
}
- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info {
self.workingImage = [info objectForKey:UIImagePickerControllerOriginalImage];
[imageView setImage:self.workingImage];
[picker dismissViewControllerAnimated:YES completion:nil];
}
- (void)didReceiveMemoryWarning {
// Releases the view if it doesn't have a superview.
[super didReceiveMemoryWarning];
// Release any cached data, images, etc that aren't in use.
}
- (void)viewDidUnload {
// Release any retained subviews of the main view.
// e.g. self.myOutlet = nil;
self.imageView = nil;
}
- (void)dealloc {
[workingImage release];
[imageView release];
[super dealloc];
}
#end
I am using Xcode 4.5.2 and designing for iOS 6.
In my BSViewController~iPad.xib I have added a "ViewController" object which upon control-clicking produces 2 Outlets: "searchDisplayController" and "view". There is no "view" top-level object; when I try to drag the "+" to the "File's Owner" I get no result and probably shouldn't.
In my BSViewController~iPhone.xib I have already a "Window" object, and don't know if that is good or needs to be also added to the the ~iPad.xib (but I don't know how).

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.

Resources