I'm newbie. I'm trying to use UITabBarController with UITableViewController (without UINavigationController), but I've faced with exception after modifying std tabbar project
Terminating app due to uncaught exception
'NSInternalInconsistencyException', reason: '-[UITableViewController
loadView] loaded the "IHHideView" nib but didn't get a UITableView.'
My didFinishLaunching
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
// Override point for customization after application launch.
UIViewController *hideViewController = [[IHHideViewController alloc] init];
UIViewController *unhideViewController = [[IHUnhideViewController alloc] init];
UIViewController *filesVIewController = [[IHFilesViewController alloc] init];
self.tabBarController = [[UITabBarController alloc] init];
self.tabBarController.viewControllers = #[hideViewController,unhideViewController,filesVIewController];
self.window.rootViewController = self.tabBarController;
[self.window makeKeyAndVisible];
return YES;
}
IHHideViewController just simplesubclass of UITableViewController
#interface IHHideViewController : UITableViewController
#end
As I know UITableViewController create own UITableView object with the correct dimensions and autoresize mask if not to specify nib file. Why such exception occurs?
It is because you are sub-classing a TableViewController. Instead change:
#interface IHHideViewController : UITableViewController
to:
#interface IHHideViewController : UIViewController
Hmmm recreating project using empty template solve problem.
Related
I'm trying to open a storyboard from my AppDelegate but it throws me the exception:
2016-10-25 10:26:16.776 momnt[22865:1300106] *** Terminating app due to
uncaught exception 'NSInternalInconsistencyException',
reason: 'Application windows are expected to have a root view
controller at the end of application launch'
Here is what i'm trying to do:
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
UIStoryboard *loginStoryboard = [UIStoryboard storyboardWithName:#"Login" bundle:nil];
UIViewController *mainViewController = [loginStoryboard instantiateInitialViewController];
self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
self.window.rootViewController = mainViewController;
[self.window makeKeyAndVisible];
return YES;
}
I've read that newer versions of XCode requires that all the Windows must have a rootViewController but i've did that.
Debug the application and check if mainViewController is not nil.
Problem seems that you don't have any viewController set as initial viewcontroller in your storyBoard.
Set any viewcontroller you want to initial viewcontroller and your code work fine.
OR
Use instantiateViewControllerWithIdentifier and pass your viewController identifier to which you want as initial viewController.
UIStoryboard *storybord = [UIStoryboard storyboardWithName:#"Login" bundle:nil];
UIViewController *mainViewController = [storybord instantiateViewControllerWithIdentifier:#"InitialViewControllerID"];
self.window.rootViewController = mainViewController;
[self.window makeKeyAndVisible];
After a few years off the grid, I'm back programming a quick iOS application and I have to say it seems I need to get back on track. :D
I'm just trying to set-up a Login view upon launching the application and I am stuck with the following issue on which I've read about a lot but could not fix it. Simulation stops on the main.m (#autoreleasepool).
FYI: I am not using Xib or Storyboard as I'm trying to do everything programmatically.
libc++abi.dyLibL terminating with uncaught exception of type NSException
It is probably coming from one of the following.
LoginViewController.h:
#interface LoginViewController : UIViewController
#end
Test1 / LoginViewController.m:
I guess there should be a init method defined from UIViewController so I would not need to define one here.
#implementation LoginViewController
#end
Test2 / LoginViewController.m:
Trying to override with my custom init function. No luck as well.
#implementation LoginViewController
- (id) init
{
self = [super initWithNibName:nil bundle:nil];
return self;
}
#end
AppDelegate.m:
self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
LoginViewController *loginViewController = [[LoginViewController init] alloc];
// error here
self.window.rootViewController = loginViewController;
[self.window makeKeyAndVisible];
return YES;
Not sure exactly what went wrong here but it crashes right after seeing a black iPhone screen on the simulator.
Any help appreciated! ;)
Thanks.
Change this line
LoginViewController *loginViewController = [[LoginViewController init] alloc];
To
LoginViewController *loginViewController = [[LoginViewController alloc] init];
Terminating app due to uncaught exception 'NSUnknownKeyException', reason: '[<UIApplication 0xa46e6a0> setValue:forUndefinedKey:]: this class is not key value coding-compliant for the key view.'
I've been researching this for the past couple of days but I haven't found an answer that gets my app to run.
I have a universal app with two nib files (one for phone, one for pad) and no matter what I change I keep running into this runtime error. I have triple-checked my connections in the Interface Builder. I also defined the main interfaces for both phone and pad respectively.
This is what my AppDelegate.m looks like:
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions: (NSDictionary *)launchOptions
{
self.window = [[[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]] autorelease];
ViewController *viewController;
if ([[UIDevice currentDevice] userInterfaceIdiom] == UIUserInterfaceIdiomPhone) {
viewController = [[ViewController alloc] initWithNibName:#"ViewController" bundle:nil];
}else {
viewController = [[ViewController alloc] initWithNibName:#"ViewController-iPad" bundle:nil];
}
self.window.rootViewController = viewController;
[viewController release];
[self.window makeKeyAndVisible];
return YES;
}
I would like to suggest to check your xib files of ViewController.
Is the custom class of file's owner set to ViewController?
and view outlet connected to file's owner?
and then try it again.
First of all, I'm a beginner, so I might have my concepts wrong.
This is my code in AppDelegate.m:
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
UIViewController *viewController = [[UIViewController alloc] initWithNibName:#"FirstView" bundle:nil];
self.navigationController = [[UINavigationController alloc] initWithRootViewController: viewController];
self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
// Override point for customization after application launch.
self.window.backgroundColor = [UIColor whiteColor];
self.window.rootViewController = self.navigationController;
[self.window makeKeyAndVisible];
return YES;
}
The idea is to programmatically add UINavigationController, but then use a .xib (the "FirstView" paremeter) for the views. I have no problem with programmatically creating the views as well, but for simpler interfaces, I assume using IB can be done as well.
However, when I run the code, I get this error:
2013-07-11 21:20:42.644 new-book-proto-01[64308:11303] *** Terminating app due
to uncaught exception 'NSInternalInconsistencyException', reason:
'-[UIViewController _loadViewFromNibNamed:bundle:] loaded the "FirstView" nib
but the view outlet was not set.'
What should I do? Is there anything missing?
Additionally, is something like this common in iOS development? Is it bad practice? Is there a better way to do this?
This is the reason as told: "reason:
'-[UIViewController _loadViewFromNibNamed:bundle:] loaded the "FirstView" nib
but the view outlet was not set.' "
It means that you try to access or get value for some views (UI elements) that has not IBOutlet in your controller class or you have none view at all
You should create IBOutlets (properties) for each view (each UI element is view) that you would like to "see" in your controller
I have tried for 2 days now to get my storyboard to display with this code:
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
UIStoryboard *storyboard = [UIStoryboard storyboardWithName:#"MainStoryboard" bundle:nil];
UIViewController *LoginViewController = [storyboard instantiateInitialViewController];
self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
self.window.rootViewController = LoginViewController;
[self.window makeKeyAndVisible];
return YES;
}
However, I keep getting this error and a sigbart in my main: 'NSInvalidArgumentException', reason: 'Could not find a storyboard named 'MainStoryboard' in bundle NSBundle (loaded)'
Nothing seems to appear in google about these errors? Does anyone have any idea how to fix it?
Update: When I change it to:
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
UIStoryboard *storyboard = [UIStoryboard storyboardWithName:#"MainStoryboard_iPhone" bundle:nil];
UIViewController *LoginViewController = [storyboard instantiateInitialViewController];
self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
self.window.rootViewController = LoginViewController;
[self.window makeKeyAndVisible];
return YES;
}
it gives me the errors:
[3208:c07] The app delegate must implement the window property if it wants to use a main storyboard file.
{AppDelegate setWindow:]: unrecognized selector sent to instance 0x962bf30
[3208:c07] * Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[AppDelegate setWindow:]: unrecognized selector sent to instance 0x962bf30'
Finally Found It!!!!!! Turns out that I forgot to put this line of code in the app delegate header file:
#property (strong, nonatomic) UIWindow *window;