This is my first interface using a button to call another xib interface
-(IBAction)poli
UIViewController *ll = [[UIViewController alloc] initWithNibName:#"ViewController" bundle:nil];
[self presentModalViewController:ll animated:YES];
and second interface calling the previous one ....
-(IBAction)popaa
UIViewController *ui = [[UIViewController alloc] initWithNibName:#"Ra" bundle:nil];
[self presentModalViewController:ui animated:YES];
but there occurs a problem that shows
terminating app due to uncaught exception 'NSUnknownKeyException', reason: [<UIViewController 0x7433230> setValue:forUndefinedKey:]: this class is not key value coding-compliant for the key pol
could someone explain the problem, i just want the first xib to show the second and second to show the first xib via a button.
Check if your xibs has any warning. Usually setValue:forUndefinedKey: is thrown when you have added some view in xib but the same is not added to your class code or the outlet is not defined properly. In this case you have added some view pol to your xib but the same is not present in your ll or ui class.
Also your dismiss method should be,
- (IBAction)popaa
[self dismissViewControllerAnimated:YES];
}
Related
i have Storyboard with UINavigationController i have created the first screen with searchbar
i have added second viewcontrol via IB to storyboard
how do i push the second viewcontroller to navigationcontroller ?
i have tried
- (void)searchBarSearchButtonClicked:(UISearchBar *)searchBar
{
[searchBar resignFirstResponder];
ViewController *screen2 = [[ViewController alloc] initWithNibName:#"ViewController2" bundle:nil];
[self.navigationController pushViewController:screen2 animated:YES];
}
i have set Custom Class of second view controller to ViewController2
but when i run the app and click the search button in keyboard i get the following error
Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'Could not load NIB in bundle: 'NSBundle (loaded)' with name 'ViewController2''
The error you are getting is because Xcode cannot find the xib named ViewController2.
You may just call self.performSegueWithIdentifier(#"identifierToViewController")
But first make sure that your searchViewController is a child of an UINavigationController
Then make sure that the segue has a proper identifier:
First of all make sure that your second view controller class name is : ViewController2
After that in storyboard give your View Controller's class name and Storyboard Id as #"ViewController2", Please refer screen shot.
Actually you use wrong method to create instance of UIViewController as it is used when you use xib file.
Change your code like this :
ViewController2 *screen2 = [self.storyboard instantiateViewControllerWithIdentifier:#"ViewController2"];
[self.navigationController pushViewController:screen2 animated:YES];
I am attempting to add a UITableViewController subclass from another storyboard into the current on as one of the tab bar view controllers.
I am using the following code which is working for other view controllers.
UIViewController *vc;
UIStoryboard *storyboard = [UIStoryboard storyboardWithName:#"MainStoryboard" bundle:nil];
if (storyboard)
{
vc = [storyboard instantiateViewControllerWithIdentifier:#"ABCCustomViewControllerStoaryboardID"];
}
This gives me the following error:
* Terminating app due to uncaught exception
'NSUnknownKeyException', reason: '[
setValue:forUndefinedKey:]: this class is not key value
coding-compliant for the key fitnessStatusView.'
The fitnessStatusView is an outlet to a subview of one of the Static cells.
If I remove the outlet connection to this subview the problem goes away.
Is it not possible to connect a view in this way? It works fine when used in the storyboard that it is created in.
Any suggestions as to what I'm doing wrong here? Thanks.
Try this code :
UIStoryboard *loStoryboard ;
loStoryboard = [UIStoryboard storyboardWithName:#"MainStoryboard" bundle:nil];
This code for navigate from AppDelegate Class..
// Instantiate the initial view controller object from the storyboard
UIViewController *initialViewController = [loStoryboard instantiateInitialViewController];
// Instantiate a UIWindow object and initialize it with the screen size of the iOS device
self.view = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
// Set the initial view controller to be the root view controller of the window object
[self.navigationController pushViewController:initialViewController animated:YES];
This code for navigate from Tabbar Controller..
UIViewController *vc = [self.storyboard instantiateViewControllerWithIdentifier:#"ABCCustomViewControllerStoaryboardID"];
[self.navigationController pushViewController:vc animated:YES];
Nope, you're not supposed to attach outlets from View Controllers to UITableViewCell subviews. Yes, I understand that the storboard allows it but it won't work in runtime as you (and I) have already found out.
I don't know why you need an outlet to a static cell subview though, because by definition, you shouldn't have to modify it because it's static.
If you really want an outlet to it, you can create a UITableViewCell subclass, assign it to the cell with the subview you want and then you can create the outlet from the subview in the storyboard to the UITableViewCell subclass. You can access the outlet in tableView:cellForRowAtIndexPath. Although that would make your table view dynamic. :)
I figured out the problem. It was related to the fact I testing another target and the table view subclass was not included in that target.
I must admit it would have been nice if I got a class not found error.
I'm trying to pass parameter from one view controller to another, but application crashes with exception.
My code is this:
SelectedItemViewController *nextView = [storyboard instantiateViewControllerWithIdentifier:#"SelectedItemViewID"];
nextView.m_selectedItemId = [NSNumber numberWithInt:777];
[self presentViewController:nextView animated:YES completion:NULL];
And I have the following in my stack:
* Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[UINavigationController setM_selectedItemId:]: unrecognized selector sent to instance 0x9c765d0'
In your storyboard, the view controller with identifier SelectedItemViewID is a navigation controller, not a SelectedItemViewController. So, before you set m_selectedItemId you should access the navigation controllers root view controller (which should be your SelectedItemViewController).
I found solution here: instantiateViewControllerWithIdentifier and pass data
What should be done in case if you want to pass parameter to view controller via navigation controller:
UINavigationController *navigationController = [storyboard instantiateViewControllerWithIdentifier:#"SelectedItemViewID"];
SelectedItemViewController *nextView = navigationController.viewControllers[0];
nextView.m_selectedItemId = [NSNumber numberWithInt:777];
[self presentViewController:navigationController animated:YES completion:NULL];
When you select the view controller in your storyboard, is the class set to SelectedItemViewController?
Obviously you seem to have a #property ... m_selectedItemId (or at least setter method setM_selectedItemId) on SelectedItemViewController, otherwise your code wouldn't even compile. But it seems that [storyboard instantiateViewControllerWithIdentifier:#"SelectedItemViewID"] doesn't really return the expected SelectedItemViewController. Hence I have the feeling that you forgot to set the correct class name to SelectedItemViewController in your storyboard.
How can I create a UIView on my previous UIViewController after popping the current UIViewController.
On my previous UIViewController I have a function that can be accessed on other UIViewControllers:
-(void)setMovieCompare:(NSString *)_movieName {
NSLog(#"Movie Compare %#",_movieName);
UIView *vw2ndPlayer = [[UIView alloc] initWithFrame:CGRectMake(0, 44, 320, 166)];
[self.view addSubView:vw2ndPlayer];
}
Then on my current UIViewController I have:
VideoPlayerViewController *_VideoPlayerViewController = [[VideoPlayerViewController alloc] initWithNibName:nil bundle:nil];
[_VideoPlayerViewController setMovieCompare:mediaObject.name];
[self.navigationController popViewControllerAnimated:YES];
It is causing me a:
*** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[__NSCFString appendString:]: nil argument'
*** First throw call stack:
(0x31a3e2a3 0x398a297f 0x31a3e1c5 0x31a0d773 0x72461 0x74077 0x33865595 0x7600b 0x7aa6d 0x3390828d 0x3398af81 0x3234c277 0x31a135df 0x31a13291 0x31a11f01 0x31984ebd 0x31984d49 0x3553b2eb 0x3389a301 0x6e89d 0x39cd9b20)
libc++abi.dylib: terminate called throwing an exception
That code crashes because it's trying to read the vc from a nibNamed:nil. Even if you got that working, it wouldn't work. The code isn't changing the VideoPlayerVC that pushed the current vc, it's just allocating a new one (trying to) and changing a view on that new one, which gets released right after that method finishes.
The way to see the presenting view controller in a navigation container is to access self.navigationController.viewControllers.
NSArray *vcs = self.navigationController.viewControllers;
VideoPlayerViewController *previousVC = vcs[MAX(0, vc.count-2)];
[previousVC setMovieCompare ...];
Reaching down the navigation array may not be the best thing, especially of other view controllers can present the current vc. An alternative design is the delegate pattern, where the VideoPlayerVC sets itself as the pushed vs's delegate before pushing.
I have a segment control in a viewcontroller (UISegmentController.h, UISegmentController.m, UISegmentController.xib) created in a xib. Now I am trying to segue (ideally push) to Storyboard viewcontroller (ChartviewController.h, ChartviewController.m) I created. This Viewcontroller will hold images. I tried to perform this push as below:
-(IBAction) segmentedControlIndexChanged;
{
//some code
ChartViewController *chartviewpage = [[ChartViewController alloc] initWithNibName:#"ChartViewController" bundle:nil];
[self.navigationController pushViewController:chartviewpage animated:YES];
//some code
}
I used to implement this code to another xib viewcontroller and it worked fine. But now not with the stroryboard viewcontroller.
However, I receive an exception as follows:
Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'Could not load NIB in bundle: 'NSBundle (loaded)' with name 'ChartViewController''
* First throw call stack:
(0x15e6012 0x11b3e7e 0x15e5deb 0x53ffac 0x404e37 0x405418 0x405648 0x405882 0x405b2a 0x41cef5 0x41cfdb 0x41d286 0x41d381 0x41deab 0x41e4a3 0x41e098 0x4048 0x11c7705 0x327920 0x3278b8 0x3e8671 0x3e8bcf 0x3e86a6 0x43d597 0x43f83b 0x35716d 0x357552 0x3353aa 0x326cf8 0x22d1df9 0x22d1ad0 0x155bbf5 0x155b962 0x158cbb6 0x158bf44 0x158be1b 0x22d07e3 0x22d0668 0x32465c 0x1d0d 0x1c35)
libc++abi.dylib: terminate called throwing an exception
(lldb)
Can u help please?
Thanks very much!
I finally figured it out doing a bit more research. first, one needs to instantiate the controller (ChartViewcontroller) in the storyboard they are trying to transition to. Then you need to give a storyboard ID name (ChartID) to the controller which can be find under the file inspector after selecting the controller. Finally perform the push to the new controller.
Hope this helps someone.
UIStoryboard * myStoryboard = [UIStoryboard storyboardWithName:#"MainStoryboard" bundle:nil];
ChartViewController *chartpage = [myStoryboard instantiateViewControllerWithIdentifier:#"ChartID"];
// Pass the selected object to the new view controller.
[self.navigationController pushViewController:chartpage animated:YES];