I am having issues switching between view controllers.
My md360AppDelegate.h header looks like this
#import <UIKit/UIKit.h>
#class md360ViewController;
#interface md360AppDelegate : UIResponder <UIApplicationDelegate>
#property (strong, nonatomic) UIWindow *window;
#property (strong, nonatomic) md360ViewController *viewController;
#property (strong, nonatomic) UINavigationController *navigationController;
#end
and my md360AppDelegate.m implementation looks like this.
#import "md360AppDelegate.h"
#import "md360ViewController.h"
#implementation md360AppDelegate
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
// Override point for customization after application launch.
self.viewController = [[md360ViewController alloc] initWithNibName:#"md360ViewController" bundle:nil];
self.navigationController = [[UINavigationController alloc] initWithRootViewController:self.viewController];
[self.navigationController setNavigationBarHidden:YES animated:YES];
[self.window setRootViewController:self.navigationController];
[self.window makeKeyAndVisible];
return YES;
}
#end
i am creating an instance of UINavigationController and storing it in navigationController property of this class.
I want to change the ViewController when a user click on a button in md360ViewController.
My md360ViewController.h looks like this.
#interface md360ViewController : UIViewController
#property IBOutlet UIButton *homePathwayBtn;
#property IBOutlet UIButton *homeDiseaseBtn;
#property IBOutlet UIButton *homePipelineBtn;
- (IBAction)homeButton:(id)sender;
#end
and my implementation looks something like
#import "md360ViewController.h"
#import "md360AppDelegate.h"
#import "pipeViewDisease.h"
#import <QuartzCore/QuartzCore.h>
- (IBAction)homeButton:(id)sender {
UIViewController *pipeViewDisease = [[UIViewController alloc] initWithNibName:#"pipeViewDiease" bundle:nil];
[self.navigationController pushViewController:pipeViewDisease animated:YES];
}
and when i click on UIButton the application crash with following message.
Terminating app due to uncaught exception
'NSInternalInconsistencyException', reason: 'Could not load NIB in
bundle: 'NSBundle
(loaded)' with name 'pipeViewDiease''
what could be the issue?
Probably just a misspelled NIB name:
initWithNibName:#"pipeViewDiease"
should be:
initWithNibName:#"pipeViewDisease"
^
Unless it's a spelling mistake (should be pipeViewDisease), this error usually occurs when files are re-named outside of the xCode environment.
To fix this:
remove the file in question from the project
re-import the files to your project.
Related
I'm using the SWViewController Library. When implementing the library, my frontViewController shows up but my rearViewController is black. I don't know what's causing this issue and could use some help with it. The app is entirely programmed in Objective C. There is no swift and no storyboards with this app.
Here is my code for rearViewController.h:
#import <UIKit/UIKit.h>
#interface RearViewController : UIViewController <UITableViewDelegate, UITableViewDataSource>
#property (nonatomic, retain) IBOutlet UITableView *rearTableView;
#end
rearViewController.m:
#import "RearViewController.h"
#import "SWRevealViewController.h"
#interface RearViewController()
{
NSInteger _presentedRow;
}
#end
#implementation RearViewController
#synthesize rearTableView = _rearTableView;
#pragma mark - View lifecycle
- (void)viewDidLoad
{
[super viewDidLoad];
self.title = NSLocalizedString(#"Rear View", nil);
}
my code for appDelegate.h:
#class SWRevealViewController;
#interface AppDelegate : UIResponder <UIApplicationDelegate>
#property (strong, nonatomic) UIWindow *window;
#property (strong, nonatomic) TARootViewController *rootViewController;
#property (strong, nonatomic) SWRevealViewController *viewController;
#property (readonly, strong, nonatomic) NSManagedObjectContext *managedObjectContext;
#property (readonly, strong, nonatomic) NSManagedObjectModel *managedObjectModel;
#property (readonly, strong, nonatomic) NSPersistentStoreCoordinator *persistentStoreCoordinator;
- (void)saveContext;
- (NSURL *)applicationDocumentsDirectory;
#end
and my code for appDelegate.m:
#import "AppDelegate.h"
#import "SWRevealViewController.h"
#import "RearViewController.h"
#interface AppDelegate()<SWRevealViewControllerDelegate>
#end
#implementation AppDelegate
#synthesize window = _window;
#synthesize viewController = _viewController;
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
UIWindow *window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
self.window = window;
RearViewController *rearViewController = [[RearViewController alloc] init];
TARootViewController *frontViewController = [[TARootViewController alloc] init];
SWRevealViewController *revealController = [[SWRevealViewController alloc] initWithRearViewController:rearViewController frontViewController:frontViewController];
revealController.delegate = self;
self.window.rootViewController = revealController;
[self.window makeKeyAndVisible];
if (self.rootViewController.activeViewController == nil) {
[[TAActiveUserManager sharedManager] startOrResumeAppSession];
}
// Register device for push notifications
UIUserNotificationType userNotificationTypes = (UIUserNotificationTypeAlert |
UIUserNotificationTypeBadge |
UIUserNotificationTypeSound);
UIUserNotificationSettings *settings = [UIUserNotificationSettings settingsForTypes:userNotificationTypes
categories:nil];
[application registerUserNotificationSettings:settings];
[application registerForRemoteNotifications];
return YES;
}
there is more here but it's not relevant to initializing the viewcontrollers
I asked this on reddit as well, and here is the thread that answered my question.
It turns out that black is the default viewController color for SWRevealViewController - just because it's black doesn't mean that it's not loading properly.
This has had happened to me before. The default background color for view controllers is clear. make sure you have your background or at least your window's background color set. In AppDelegate.m:
self.window.backgroundColor = [UIColor whiteColor];
Also, I'm assuming you want a navigation controller in their since your setting a view controllers self.title property. The title will show up in the Navigation bar when that particular view controller is on top of the stack. It is simple to imbed your view controller into a navigationController. Replace this with the line where you set your rootViewController.
self.window.rootViewController = [[UINavigationController alloc] initWithRootViewController:revealController];
It has been a while since I created a project from scratch. Back then in XCode 4 / 5 the developer was given the choice between storyboard or Xib to get the project started. In Xcode 6 though every template is forced to get started as StoryBoard.
I have removed the story board. Then I have opened info.plist in Supporting files and set Main storyboard file base name : Main to Main storyboard file base name: <blank>.
Then I created a basic testViewController with Xib (same name).
#interface AppDelegate : UIResponder <UIApplicationDelegate>
#property (nonatomic, retain) IBOutlet UIWindow *window;
#property (nonatomic, retain) IBOutlet UINavigationController *navigationController;
#end
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
testViewController *firstViewController = [[testViewController alloc] initWithNibName:nil bundle:nil];
self.navigationController.viewControllers = [NSArray arrayWithObject:firstViewController];
self.window.rootViewController = self.navigationController;
[self.window makeKeyAndVisible];
return YES;
}
And this still shows me a black view controller. I checked the xib file, the File owner is set to the view controller and the view delegate is also set.
What am I missing please?
change these two things:
#property (nonatomic, retain) IBOutlet UIWindow *window;
testViewController *firstViewController = [[testViewController alloc] initWithNibName:nil bundle:nil];
To this, and add this code, with the real name or you xib file:
#property (nonatomic, retain) UIWindow *window; // Are you using ARC?
self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
// I think your xib files is testViewcontroller.xib, if not change it.
testViewController *firstViewController = [[testViewController alloc] initWithNibName:testViewController.xib bundle:nil];
// change this also
self.navigationController = [[UINavigationController alloc] initWithRootViewController:firstViewController];
self.window.rootViewController = self.navigationController;
[self.window makeKeyAndVisible];
return YES;
I have a problem in AppDelegate, when run the app I get this error:
Terminating app due to uncaught exception 'NSUnknownKeyException', reason:
'[<UIApplication 0x856c820> setValue:forUndefinedKey:]:
this class is not key value coding-compliant for the key view.'
This is the code of AppDelegate.h
#import <UIKit/UIKit.h>
#class ViewController;
#interface AppDelegate : UIResponder <UIApplicationDelegate>{
//UINavigationController *navigationController;
}
#property (strong, nonatomic) UIWindow *window;
#property (copy, nonatomic) ViewController * viewController;
#property (copy, nonatomic) UINavigationController * navigationController;
#end
This is the code of AppDelegate.m
#import "AppDelegate.h"
#import "RootViewController.h"
#implementation AppDelegate
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions: (NSDictionary *)launchOptions
{
self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
RootViewController *rootMenu;
if ([[UIDevice currentDevice] userInterfaceIdiom] == UIUserInterfaceIdiomPhone) {
rootMenu= [[RootViewController alloc] initWithNibName:#"ViewController_iPhone" bundle:nil];
} else {
rootMenu = [[RootViewController alloc]initWithNibName:#"ViewController_iPad" bundle:nil];
}
self.navigationController =[[UINavigationController alloc]initWithRootViewController:rootMenu];
self.window.rootViewController = self.navigationController;
[self.window makeKeyAndVisible];
return YES;
}
What can I do to resolve this error? I have rewritten the RootViewController, throwing in the trash the old one, but the problem remains the same.Thanks in advance
This usually happens when an Interface Builder or Storyboard connection hasn't properly been made. Sometimes you'll make a connection, and then delete the code that the connection was made to. Interface Builder still has a reference to the code, which causes the key/value compliant run time error. You can also get this error if you haven't assigned the proper class to a view controller. If you've written code for a particular view controller, be sure to set the class appropriately in Interface Builder for that View Controller.
I know this question is a bit old, but I was running into the same problem and the article below helped a lot. Basically it illustrates step-by-step how to fix the problem #bgolson described.
http://www.tech-recipes.com/rx/52021/how-do-i-fix-the-issue-this-class-is-not-key-value-coding-compliant-for-the-key-in-xcode-6/
I have a file named MMAppDelegate.m:
#import "MMAppDelegate.h"
#implementation MMAppDelegate
#synthesize window;
#synthesize viewController;
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
viewController = [[MainViewController alloc] init];
[window addSubview:viewController.view];
// Override point for customization after application launch.
[window makeKeyAndVisible];
return YES;
}
//and more standard methods
MMAppDelegate.h:
#import <UIKit/UIKit.h>
#import "MainViewController.h"
#interface MMAppDelegate : UIResponder <UIApplicationDelegate> {
UIWindow *window;
MainViewController *viewController;
}
#property (nonatomic, retain) UIWindow *window;
#property (nonatomic, retain) MainViewController *viewController;
#end
MainViewController.m:
#import "MainViewController.h"
#implementation MainViewController
- (void)viewDidLoad {
NSLog(#"view did load main view controller");
[super viewDidLoad];
self.view.backgroundColor = [UIColor redColor];
}
#end
And yet when I run the program, I get a black screen, and the output:
2012-02-12 15:44:48.160 MoreMost[44076:f803] view did load main view controller
2012-02-12 15:44:48.163 MoreMost[44076:f803] Applications are expected to have a root view controller at the end of application launch
What is the problem?
Change this line:
[window addSubview:viewController.view];
to this:
window.rootViewController = viewController;
And you'll need to create the window, like this:
window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
You don't need/want to add the view controller's view as a subview. You want to make your controller the root view controller and iOS will take care of the rest:
window.rootViewController = viewController;
That is, as of iOS 4. (Not sure the answer if you're going back earlier than that.)
You also need to create the window before you use it. Something like
window = [[UIWindow alloc] initWithFrame:UIScreen.mainScreen.bounds];
Not sure if you aren't or if you just didn't show it ...
I've been banging my head against this all day, it seems like something simple but I can't figure it out.
I've got an iOS app that I created using the "View-based Application" template in XCode. Here is essentially the code I have:
AppDelegate.h:
#import <UIKit/UIKit.h>
#interface AppDelegate : NSObject <UIApplicationDelegate> {
UIWindow *window;
MainViewController *viewController;
}
#property (nonatomic, retain) IBOutlet UIWindow *window;
#property (nonatomic, retain) IBOutlet MainViewController *viewController;
#end
AppDelegate.m:
#import "AppDelegate.h"
#import "MainViewController.h"
#implementation AppDelegate
#synthesize window, viewController;
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
[self.window addSubview:viewController.view];
[self.window makeKeyAndVisible];
return YES;
}
- (void)dealloc {
[viewController release];
[window release];
[super dealloc];
}
#end
MainViewController.h:
#import <UIKit/UIKit.h>
#interface MainViewController : UIViewController {
}
-(IBAction) button:(id)sender;
#end
MainViewController.m:
#import "MainViewController.h"
#import "ModalViewController.h"
#implementation MainViewController
...
-(IBAction) button:(id)sender {
ModalViewController *mvc = [[[ModalViewController alloc] initWithNibName:NSStringFromClass([ModalViewController class]) bundle:nil] autorelease];
[self presentModalViewController:mvc animated:YES];
}
#end
There's nothing of interest in the ModalViewController.
So the modal view should display when the button is pressed. When I press the button, it hangs for a second then crashes back to the home screen with no error message.
I am stumped, please show me what I'm doing wrong!
There's nothing of interest in the ModalViewController.
Although there may not be anything of interest, there could still be something causing the problem.
Does your View Controller override the function loadView?
A problem that has got me a few times is if you don't call [super loadView]; first in your overriden loadView method. Not doing this causes a crash when moving into that View Controller.
Good luck in trying to solve this one!
N