So I am pretty new to this story board concept. I have a view nibs dropped in to the storyboard and each corresponding to a UIViewController subclass I have, I tried loading the nib file using the following code:
TestViewController *vc = [[TestViewController alloc] initWithNibName:#"TestViewController" bundle:nil];
[self.view setBackgroundColor:[UIColor blueColor]];
[self.view setFrame:CGRectMake(0, self.profilePicture_.frameHeight + self.profilePicture_.frameY + 10, self.scrollView_.frameWidth, 100)];
[self.view addSubview:vc.view];
However, it gives me the following error:
*** Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'Could not load NIB in bundle: 'NSBundle </Users/aditya15417/Library/Application Support/iPhone Simulator/5.1/Applications/64E6CEC9-E6DC-4AF5-BF16-11BFB6415BDC/Pulse.app> (loaded)' with name 'TestViewController''
So the question is, if I have my nib in the story board is it not possible to use the initWithNibName? If there is a way, how do I do this?
Please use
[self.storyboard instantiateViewControllerWithIdentifier:#"some identifier you set in IB"];
Why are you loading PNRNewsfeedViewController as TestViewController? Is TestViewController the base class for PNRNewsfeedViewController? Make sure that in the nib, the File's Owner custom class is set to PNRNewsfeedViewController, and then allocate a news feed view controller:
PNRNewsfeedViewController *vc = [[PNRNewsfeedViewController alloc] initWithNibName:#"PNRNewsfeedViewController" bundle:nil];
// ...
When you use a storyboard, you don't use individual nibs directly, and you don't instantiate view controllers yourself. You can use the UIStoryboard class to instantiate a view controller from the storyboard as described in the documentation.
This is the way I'd do it:
UIStoryboard *storyBoard = [UIStoryboard storyboardWithName:#"MainStoryboard" bundle:[NSBundle mainBundle]];
Related
In my application, I made custom tab bar having 5 tabs, each tab shows different UIViewController.
Application is for iPhone only, so i made 2 NIBs for each UIViewController (if class name is DayView, NIBs are DayView_iPhone and DayView_iPhone5). Everything is working fine for up to 10 mins in the device as well as in simulator.
After that app is crashing showing this in console :
Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'Could not load NIB in bundle: 'NSBundle </Users/kalyanasadinagarajugari/Library/Application Support/iPhone Simulator/6.1/Applications/0DEBB118-BA67-440F-BA70-79ED41AC9134/CalendarBlender.app> (loaded)' with name 'DayView_iPhone''
I checked the NIB names also, every NIB file name is correct.
And my code is
NSString *nibName = [AppDelegate fetchNibWithViewControllerName:#"DayView"];
dayView = [[DayView alloc] initWithNibName:nibName bundle:nil];
if (IS_IPHONE_5)
dayView.view.frame = CGRectMake(0, 44, 320, 463);
else
dayView.view.frame = CGRectMake(0, 44, 320, 375); dayView.view.tag=2; [self.view
addSubview:dayView.view];
Try to check the Nibname (Case Sensitive) and clean the project,re run it . Did you changed the class name for all the nibs?
Use this:
- (void)applicationDidFinishLaunching:(UIApplication *)application {
tabBarController = [[UITabBarController alloc] init];
MyViewController* vc1 = [[MyViewController alloc] initWithNibName:#"nibName" bundle:nil];
MyOtherViewController* vc2 = [[MyOtherViewController alloc] initWithNibName:#"nibName" bundle:nil];
NSArray* controllers = [NSArray arrayWithObjects:vc1, vc2, nil];
tabBarController.viewControllers = controllers;
window.rootViewController = tabBarController;
}
And you can add controllers dynamically too by adding controllers in tabBarController's array of viewControllers.
here is my code:
I using storyboards
NewsDetailViewController *newsdetail=[[NewsDetailViewController alloc] initWithNibName:nil bundle:nil];
newsdetail.modalTransitionStyle=UIModalTransitionStyleFlipHorizontal;
[self presentModalViewController:newsdetail animated:YES];
I have a collectionview i fetched some datas from api and put them to the cells of collectionview. I want to get details of items that i clicked on cell but after click details doesn't work but black screen is coming.
here is my all output :
2013-06-17 14:20:30.288 xproject[7511:c07] *** Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'Could not load NIB in bundle: 'NSBundle </Users/sezgindemir/Library/Application Support/iPhone Simulator/6.1/Applications/67BC91AF-5091-4F39-A2BD-CA7E1DD0FEF0/xproject.app> (loaded)' with name 'NewsDetailViewController''
*** First throw call stack:
(0x1c99012 0x10d6e7e 0x1c98deb 0x236ef9 0xfb7e7 0xfbdc8 0xfbff8 0xfc232 0x107c25 0x3073a3 0x104ee3 0x105167 0x1051a7 0x4c3d 0x51c42f 0x52e182 0x52e394 0x10ea705 0x12893c 0x1289ac 0x10ea705 0x12893c 0x1289ac 0x2e21d3 0x1c61afe 0x1c61a3d 0x1c3f7c2 0x1c3ef44 0x1c3ee1b 0x1bf37e3 0x1bf3668 0x1affc 0x25ed 0x2515)
libc++abi.dylib: terminate called throwing an exception
(lldb)
Is the xib for NewsDetailViewController in storyboard or separate xib?
If it is a separate xib, make sure your xib name is NewsDetailViewController.xib. Then it should work.
If the nib is in storyboard the
first set the storyboardID of the xib to NewsDetailViewController and then use
NewsDetailViewController *newsdetail=[[self storyboard] instantiateViewControllerWithIdentifier:#"NewsDetailViewController"];
newsdetail.modalTransitionStyle=UIModalTransitionStyleFlipHorizontal;
[self presentModalViewController:newsdetail animated:YES];
You're not loading view controller properly.
Try this code:
UIViewController *vc=[[self storyboard] instantiateViewControllerWithIdentifier:#"NewsDetail"];//you have to give it this name (or any) in the storyboard
[self.navigationController pushViewController:vc animated:YES];
Make sure you have a uinavigationController controlling self
I think you missed to provide the NibName
Your code
NewsDetailViewController *newsdetail=[[NewsDetailViewController alloc] initWithNibName:nil bundle:nil];
It should be
NewsDetailViewController *newsdetail=[[NewsDetailViewController alloc] initWithNibName:#"YOUR_NIB_NAME" bundle:nil];
Use this -
NewsDetailViewController *news detail = [[NewsDetailViewController alloc] init];
I am using PaperFoldMenuController to create a cool SlideMenu in my App.
In the AppDelegate I define the viewControllers and add them to the SlideMenu Array:
// Init viewControllers
RootViewController *rootViewController = [[RootViewController alloc] init];
LivetickerViewController *livetickerViewController = [[LivetickerViewController alloc] init];
// Add view controllers to array
[viewControllers addObject:rootNavController];
[viewControllers addObject:livetickerNavController];
// Add to PaperFoldView
[_menuController setViewControllers:viewControllers];
I use a storyboard for designing most parts of the LivetickerViewController. But all changes are not shown. I checked that Storyboard is connected with the view.
What is the problem in the code ?
If you've designed your LivetickerViewController in the storyboard, then you need to get it from the storyboard not with alloc init.
UIStoryboard *storyboard = [UIStoryboard storyboardWithName:#"MainStoryboard" bundle:nil];
LivetickerViewController *livetickerViewController = [storyboard instantiateViewControllerWithIdentifier:#"livetickerViewController"];
Make sure that the name of the storyboard is what is actually in your project, and that you have given the view controller an identifier that matches what you pass in the instantiateViewControllerWithIdentifier: method.
If you made rootViewController in the storyboard, you should do the same thing with it.
I'm trying to switch views in an iPhone application, but whenever I click on the button to bring up the second view, all I get is a blank screen, even though I've filled the view with buttons and whatnot.
I've checked the second ViewController in my storyboard file and its custom class is the one that it needs to be (When I originally created the second ViewController class a new interface file came with it, which I promptly deleted). What might I be doing wrong?
- (IBAction)Transition_NEXT:(id)sender
{
nextViewController = [[NextViewController alloc]
initWithNibName:#"NextViewController"
bundle:[NSBundle mainBundle]];
[self presentModalViewController:nextViewController animated:NO];
}
I don't think you're using Storyboards correctly. You shouldn't be using initWithNibName, as that's the old method of instantiating a view controller. Try using the new instantiateViewControllerWithIdentifier like so:
UIStoryboard *storyboard = [UIStoryboard storyboardWithName:#"MainStoryboard" bundle:[NSBundle mainBundle]];
UIViewController *nextView = [storyboard instantiateViewControllerWithIdentifier:#"NextViewController"];
[self.view presentModalViewController:nextView animated:YES];
If you already have a reference to your storyboard in your controller, then you shouldn't initialize a new one, but instead you should just use the reference you have.
UIViewController *nextView = [self.storyboard instantiateViewControllerWithIdentifier:#"NextViewController"];
[self.view presentModalViewController:nextView animated:YES];
Compiling my application works—everything is fine. The only errors I get are by deprecated functions (setText).
The only problem is now, is that when I tap on a cell in my table, the app crashes, even though it's meant to push to the next view in the stack.
Any solutions are appreciated, if you need any code, just ask.
Also, how can I only make sure that one cell goes to only one view? For example:
When I tap on CSS, it takes me to a new table with different levels of CSS. WHen I tap on an item in that new view, it comes up with an article on what I just selected.
Regards,
Jack
Here's my code at the didSelectRowAtIndexPath method:
-(void)tableView:(UITableView *)tableView
didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
if(indexPath.row==0){
NextViewController *nextController = [[NextViewController alloc]
initWithNibName:#"NextView" bundle:nil];
[self.navigationController pushViewController:nextController
animated:YES];
[nextController changeItemTable:[arryClientSide
objectAtIndex:indexPath.row]];
}
}
#end
(as requested in the comments).
When we create new UIViewControllerSubClass with xib-interface, xib file is created as sourcecode.xib (can be seen in get info of that xib file): Change sourcecode.xib to "file.xib" and see the magic :)
Terminating app due to uncaught
exception
'NSInternalInconsistencyException',
reason: -[UIViewController
_loadViewFromNibNamed:bundle:] loaded the "NextView" nib but the view outlet
was not set.'
Open NextView with Interface Builder
Set Class value at : "NextViewController" to your File's Owner
Connect the View outlet (Ctrl click and drag - a blue line should appear - from the File Owner to the UIView and select "view" in options)
you need to update your code like this :
-(void)tableView:(UITableView *)tableView
didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
if(indexPath.row==0){
NextViewController *nextController = [[NextViewController alloc]
initWithNibName:#"NextView" bundle:nil];
[nextController changeItemTable:[arryClientSide
objectAtIndex:indexPath.row]];
[self.navigationController pushViewController:nextController
animated:YES];
}
else{ }
}
try using this code...
Error description from comments:
Terminating app due to uncaught
exception
'NSInternalInconsistencyException',
reason: '-[UIViewController
_loadViewFromNibNamed:bundle:] loaded the "NextView" nib but the view outlet
was not set.'
If your view controller is loaded from nib file and its view is not set exception then exception is thrown. So when you create your view in IB you must connect view outlet to your view controller object (likely - file owner in IB).
Edit: So basically in IB in your nib file you need to do the following:
1. set file owner's type to NextViewController
2. connect NextViewController's view outlet to a View object
release that NextViewController you alloc!
[nextController release];
It's leaking.
Don't use IB. Instead, make alloc init with nothing, then in load view:
self.view = [[[UIView alloc] initWithFrame:[[UIScreen mainScreen] applicationFrame]] autorelease];