i've got a UIViewControllers with two UIButtons, i want to know how to pass from this UIViewController to my UIPageViewController,
i tried to link the UIButton to my UIPageViewController from the storyboard but it gives me this error
Terminating app due to uncaught exception
'NSInvalidArgumentException', reason: 'Storyboard () doesn't contain a view controller with identifier
'Guide''
how should i do?
EDIT
- (IBAction)goToGuide:(id)sender{
[self performSegueWithIdentifier:#"goToGuide" sender:self];
}
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
{
if ([[segue identifier] isEqualToString:#"nextView"])
{
FirstLaunch *fLaunch = [segue destinationViewController];
//pass any data to next view here
}
}
Added this to my UIViewController and added the identifier in my storyboard a connection between the view controller and the UIPageViewController and set the identifier to goToGuide, but same error..
UP
EDIT2
- (IBAction)goToGuide:(id)sender{
[(UINavigationController*)self.window.rootViewController pushViewController:Guide animated:YES];
[self performSegueWithIdentifier:#"NextView" sender:self];
}
It says, property windows not found on object of type FirstLaunch
Give the segue identifer in the storyboard, you must have missed it.
Check this answer
ios automatically segue from one screen to another
Related
On my app I decided to change my segue to a Show Details segue in the story board as I wanted the affect of the storyboard coming from the bottom of the screen, and thus I needed some way to bring the user back, so I inserted a navigation into the destination view. However now I get:
Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[UINavigationController setImageData:]: unrecognized selector sent to instance 0x7fbdfa887600'
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
{
// Make sure your segue name in storyboard is the same as this line
if ([[segue identifier] isEqualToString:#"infoSegue"])
{
// Get reference to the destination view controller
DetailsViewController *vc = [segue destinationViewController];
// Pass any objects to the view controller here, like...
int num = (int)[self getIndexNum];
NSString *dictionaryKey = _results[num];
Image *image = _dataDictionary[dictionaryKey];
vc.imageData = image;
NSLog(#"Vendor ID %#",image.vendorId);
}
}
Has the navigation become the parent of the view or something?
As destinationViewController returns the generic type UIViewController you have to do a type cast.
DetailsViewController *vc = (DetailsViewController *)[segue destinationViewController];
if your destination view controller is a navigation controller, then you shouldn't set the image on navigation controller!! Also as #vadian from the answer said, you need to cast the return type of uiviewcontroller!!!
UINavigationController *navController = [segue destinationViewController];
DetailsViewController *viewController = (DetailsViewController *)([navController viewControllers][0]);
[viewController setimageData:image];
Make sure imageData is of kind UIImage. If it is of type NSData, you might need to do:
[viewController setimageData:[UIImage imageWithData:imageData]];
I have a problem with a segue. I have "next" button:
- (IBAction)NextButton:(id)sender {
//...
[self performSegueWithIdentifier:#"adaugaScore" sender:self];
}
and this:
-(void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender{
if ([[segue identifier] isEqualToString:#"adaugaScore"])
{
ScoreViewController *scoreVC = segue.destinationViewController;
scoreVC.score = [NSString stringWithFormat:#"%d",score];
}
}
My app crashes at this line:
[self performSegueWithIdentifier:#"adaugaScore" sender:self];
With this error:
has no segue with identifier 'adaugaScore''
You need to set storyboard id/name(adaugaScore) in your storyboard to your controller. Check : What is a StoryBoard ID and how can i use this? for more information.
EDIT :
To use the segue name refer : How do i set a modal segue (programmatically) to a push segue
Set the segue.identifier to be adaugaScore. This is done by clicking the segue and in the properties panel setting the identifier.
Question was solved! See the code at the bottom.
I'd like to pass some data between 2 controllers. I have MainViewController class where GoogleMap is loaded. On click at custom info window for each GMap's marker I want to open new window with place details.
My storyboard is:
Segue was named: showPlaceDetails:
Several methods was written:
- (void) mapView:(GMSMapView *)mapView didTapInfoWindowOfMarker:(GMSMarker *)marker {
[self performSegueWithIdentifier:#"showPlaceDetails" sender: nil];
}
(I also tried to use sender: [marker snippet]).
My prepareForSegue method:
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
if ([segue.identifier isEqualToString:#"showPlaceDetails"]) {
//[[segue destinationViewController] setDelegate:self];
PlaceDetailsViewController *destViewController = segue.destinationViewController;
//Pass some data
}
}
But I got the message:
Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: 'Receiver (RelaxInKZViewController) has no segue with identifier 'showPlaceDetails''
I did these steps:
Add New View Controller on storyboard.
Add Objective-C Class called PlaceDetailsViewController.
Change custom class of newly added VC to "PlaceDetailsViewController"
Add that code
Clear Simulator's data and clean project
And nothing. I hope you can help me :)
Thx, Artem.
Mr_bem has adviced me to refuse segues and use pushViewController method. It's good!
UIStoryboard *iPhoneStoryboard = [UIStoryboard storyboardWithName:#"Main_iPhone" bundle:nil];
PlaceDetailsViewController *destViewController = [iPhoneStoryboard instantiateViewControllerWithIdentifier:#"PlaceDetailsViewController"];
destViewController.placeData = marker.placeData;
[self.navigationController pushViewController:destViewController animated:NO];
You are using a Push segue, this can only be performed with a navigationController, like:
[self.navigationController performSegueWithIdentifier:#"showPlaceDetails" sender: nil];
Note you should have a navigation controller before your ViewController, the one that pushes.
Or if you want, you can change its type to Modal, everything should work great for you (Y)
UPDATE
Okay, here's what I propose, remove the segue, make the storyboardID of your PlaceDetailsViewController to PlaceDetailsViewController from the IB, and add this code instead
- (void) mapView:(GMSMapView *)mapView didTapInfoWindowOfMarker:(GMSMarker *)marker {
PlaceDetailsViewController *destViewController = [self.storyboard instantiateViewControllerWithIdentifier:#"PlaceDetailsViewController"];
[self.navigationController pushViewController:destViewController animated:YES]
se
}
THIS MUST WORK! LOL!
You need to embed your RelaxInKZViewController inside UINavigationController to use push segue. Select RelaxInKZViewController-> from the menu at the top select Editor->Embed In->Navigation Controller. I think that will solve your problem.
Firstly, I use storyboard to create two uiviewcontroller: firstviewcontroller and secondviewcontroller. And using xcode to embed a uinavigationcontroller into secondviewcontroller(editor --> embed in --> navigation controller). Then, I also want to use segue to pass value from first to second. there is the code:
-(void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
{
if([segue.identifier isEqualToString:#"passValue"])
{
secondViewController *saveViewController = [segue destinationViewController];
[saveViewController setValue:data forKey:#"data"];
}
}
But there will report error, the log is:
Terminating app due to uncaught exception 'NSUnknownKeyException', reason: '[ setValue:forUndefinedKey:]: this class is not key value coding-compliant for the key data.'
However, when I delete the navigation controller that I use Xcode to insert it and define the navigation bar by code, this problem will disappear. I guess the reason is the real destinationViewController is navigationcontroller instead of secondviewcontroller. So if I want to reserve the navigation controller that is embedded by Xcode, how can fix this problem?
You're right, destinationViewController will be a UINavigationController you have secondViewController embeded in. Maybe try that:
secondViewController *saveViewController = [[segue destinationViewController] topViewController];
This question already has answers here:
Closed 10 years ago.
Possible Duplicate:
How can I pass image ID to next view by using Storyboards in iOS
My code is:
- (IBAction) buttonPressed:(id)sender
{
UIStoryboard *storyboard = [UIStoryboard storyboardWithName:#"MainStoryboard" bundle: nil];
DestinationViewController *destinationViewController = [storyboard instantiateViewControllerWithIdentifier:#"Destination"];
destinationViewController.title = #"image property";
[self.navigationController pushViewController:destinationViewController animated:YES];
[destinationViewController release];
}
But i got error is:
Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: 'Storyboard (<UIStoryboard: 0x68a0840>) doesn't contain a view controller with identifier 'Destination''
First throw call stack:
(0x13d4022 0x1565cd6 0x448fef 0x39f6 0x13d5e99 0x2114e 0x210e6 0xc7ade 0xc7fa7 0xc7266 0x463c0 0x465e6 0x2cdc4 0x20634 0x12beef5 0x13a8195 0x130cff2 0x130b8da 0x130ad84 0x130ac9b 0x12bd7d8 0x12bd88a 0x1e626 0x2902 0x2875)
terminate called throwing an exception(lldb)
Any thoughts?
Thanks in advance.
You need to set the view controller's identifier to "Destination" in IB. The following iextracted from Apple's document on UIStoryBoard.
An identifier string that uniquely identifies the view controller in the storyboard file. You set the identifier for a given view controller in Interface Builder when configuring the storyboard file. This identifier is not a property of the view controller object itself and is only used by the storyboard file to locate the view controller.
The answer involving setting the identifier correctly is probably your problem. However, it seems like you're doing this in a kind of hacky way by getting a reference to the storyboard and having it instantiate the controller.
Instead, try creating a push segue between the view controller and the DestinationViewController in the storyboard editor and do this:
- (IBAction)buttonPressed:(id)sender {
[self performSegueWithIdentifier:#"yourSegueIdentifierHere"];
}
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
DestinationViewController *controller = [segue destinationViewController];
[controller setImage: ... ];
}
You can use the
(void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
method to pass data between view controllers using
myViewController *viewController = [segue destinationViewController];
to specify your destination.