Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

nichlaspro

macrumors member
Original poster
Jan 21, 2015
82
1
I've got a very big problem!

I can segue from storyboard to xib file like this: (image) http://s14.postimg.org/xgq004vsh/screen.png

This is all working fine but this doesn't:

Ok, now i'm in the xib file and want to get back to the main storyboard or just the previous view if that makes a difference..But that is not working at all, it crashes when i do it, look at the image and you can see the log and the code i'm using (the "Back" function): http://s4.postimg.org/wi3myjgjh/screen2.png And it crashes everytime! PLEASE TELL ME WHY AND WHAT I CAN DO!

Thanks!! I really appreciate help! :)

I hope this is the right category :)
 
Few comments:

Why do you need a nib file when you have a perfectly good storyboard? If you avoid using an extra nib you most likely avoid this entire problem.

If you have a navigation controller then you don't need a back button. Everything just works. I guess you have a Back button somewhere in the view controller's view that is connected to your back: action. Your code in the back: method is not correct. You need to pop your view controller not push something else.

The opposite of presentViewController:animated: seems to be dismissViewController:animated: However, if it's all in one storyboard you can use an unwind segue connected to your back button. Maybe you can do that in a nib, I'm not sure.
 
Few comments:

Why do you need a nib file when you have a perfectly good storyboard? If you avoid using an extra nib you most likely avoid this entire problem.

If you have a navigation controller then you don't need a back button. Everything just works. I guess you have a Back button somewhere in the view controller's view that is connected to your back: action. Your code in the back: method is not correct. You need to pop your view controller not push something else.

The opposite of presentViewController:animated: seems to be dismissViewController:animated: However, if it's all in one storyboard you can use an unwind segue connected to your back button. Maybe you can do that in a nib, I'm not sure.

Answer here: First of all, I have nib with the storyboard because I have been using it for long time so I like to continue and thinks it easier, but that's just my opinion..

Please help me, I do understand what u say, but can you post a code example..

I'm not sure about that pop and push stuff??

Thanks!
 
No as you add view controllers using presentViewController:animated: they 'stack', so calling dismissViewControllerAnimated will dismiss the current one and show the previous.

Do ot be scared ofthe documentation. Reading, understanding and using the apple documentation will help you really make use of all the features of Cocoa (Touch).
 
No as you add view controllers using presentViewController:animated: they 'stack', so calling dismissViewControllerAnimated will dismiss the current one and show the previous.

Do ot be scared ofthe documentation. Reading, understanding and using the apple documentation will help you really make use of all the features of Cocoa (Touch).

Thanks so much!!!!! I will try that when I get home in some hours.. So please come back in about 5 hours and then I can give u the respond! Thanks! :)
 
No as you add view controllers using presentViewController:animated: they 'stack', so calling dismissViewControllerAnimated will dismiss the current one and show the previous.

Do ot be scared ofthe documentation. Reading, understanding and using the apple documentation will help you really make use of all the features of Cocoa (Touch).

OMG, this should be so simple!!

But i wrote, [self.navigationController dismissViewControllerAnimated:YES completion:nil]; in the xib's class but now this happens: http://s7.postimg.org/hnjjmrzl7/new_Try.png

Please notice that i am using this code in sotryboard's class, to get to the xib from storyboard which is working:
Code:
ViewController *viewController=[[ViewController alloc]initWithNibName:@"Windoww" bundle:nil];
    
    [self presentViewController:viewController animated:YES completion:nil];

Why!?? what can i do?

Thanks!!!
 
Last edited by a moderator:
Mixing storyboards and nibs is not easier. It is harder than using only one or the other. It should take just a few minutes to add a scene with the segue you want and set the custom class for the view controller.

The error you show is because you have the back button action connected to the wrong view controller. In order to understand run-time-exceptions like this you have to look at the line that starts: Terminating app due to uncaught exception, reason: 'unrecognized selector' means that the code attempted to send a message to a class that doesn't implement that method. It says that the instance and method are [ViewController back:] but your code shows that the back: method is in the Window class. Either the button is connected to the wrong action or the class of the view controller in the nib or storyboard is ViewController when it should be Window.

Anyway, check all your connections and the types of all the classes of the view controllers. You can also set breakpoints in your viewDidLoad methods to see if they are hit when you expect.
 
Mixing storyboards and nibs is not easier. It is harder than using only one or the other. It should take just a few minutes to add a scene with the segue you want and set the custom class for the view controller.

The error you show is because you have the back button action connected to the wrong view controller. In order to understand run-time-exceptions like this you have to look at the line that starts: Terminating app due to uncaught exception, reason: 'unrecognized selector' means that the code attempted to send a message to a class that doesn't implement that method. It says that the instance and method are [ViewController back:] but your code shows that the back: method is in the Window class. Either the button is connected to the wrong action or the class of the view controller in the nib or storyboard is ViewController when it should be Window.

Anyway, check all your connections and the types of all the classes of the view controllers. You can also set breakpoints in your viewDidLoad methods to see if they are hit when you expect.

Ok, i can't find anything which seems wrong and i have looked up at probably everything i think, but i want to ask all the people who takes a look at this post a favor; Please download my project here(mini project):

https://drive.google.com/folderview...ZsTjZaZjlzWjByaHBMZ04xbXlmOXpPckE&usp=sharing

Then please check if you can find the reason for the error and how to fix it!
It is not because i don't know how to swith between them, i have done that for some years ago, but know i just can't get it to work:(
So please help me, this is so annoying for me, it takes all my time :(

If u want to do that for me, THANKS!
If u did read this, thanks again!
I really appreciate your time and your help!
 
Last edited:
First, rather than post images, pose code in CODE blocks. Paste in the code, select it, then click on the # mark above the edit window. This has the pay off that people can read your code without extra steps and they may copy and edit for better suggestions.

Am I missing something. You don't have a prepareForSeque:sender in the ViewController, so you are NOT using a seque to move to the next Window view. (Window is a poor name by the way for a view controller.)

As for dismissing the current view controller, try this line.
Code:
[self dismissViewControllerAnimated:YES completion:nil];
 
First, rather than post images, pose code in CODE blocks. Paste in the code, select it, then click on the # mark above the edit window. This has the pay off that people can read your code without extra steps and they may copy and edit for better suggestions.

Am I missing something. You don't have a prepareForSeque:sender in the ViewController, so you are NOT using a seque to move to the next Window view. (Window is a poor name by the way for a view controller.)

As for dismissing the current view controller, try this line.
Code:
[self dismissViewControllerAnimated:YES completion:nil];


Ok first, Thanks again for the reply, I really appreciate it!

But I can't get that to work.. I have put the download link to my project folder in my last post.. Have you tried if you can get that to work with that line because I can't and I got no idea why:((

Thanks, u r a really nice person!
 
Ok first, Thanks again for the reply, I really appreciate it!

But I can't get that to work.. I have put the download link to my project folder in my last post.. Have you tried if you can get that to work with that line because I can't and I got no idea why:((

Thanks, u r a really nice person!

That link is not useful as it is individual files of the project. From what I did see, there isn't much to this project. Looks like a test case. To be useful, use the Finder to Compress your project into a Zip file and upload that to your G Drive. Can't guarantee I'll look at, but perhaps some will.
 
That link is not useful as it is individual files of the project. From what I did see, there isn't much to this project. Looks like a test case. To be useful, use the Finder to Compress your project into a Zip file and upload that to your G Drive. Can't guarantee I'll look at, but perhaps some will.

I have updated the link, it should work be the project folder now..Just right click and download;-)

Thanks!
 
The only time you're using a Segue is when initially loading the "ViewController". The system is doing that for you, due to the setup of the project.

Here are your issues with the code.

First, ViewController.h needs to import the definition for your Windoww view controller.
Code:
#import "Windoww.h"

Second ViewController.m needs to instantiate your Windoww subclass of ViewController. The reason for the crash is because your call to return to the first view controller is calling a method, back:, that is only available in your subclass. Even though you are loading the right XIB file, you have not allocated the proper class for the new view controller, therefore the call is going to a declaration of the standard ViewController class. The proper line is;
Code:
UIViewController *viewController=[[Windoww alloc]initWithNibName:@"Windoww" bundle:nil];

Third, when trying to exit the "Window" screen, you are not using a navigation controller so are making the wrong the call. As I mentioned before you need to replace that line with the following.
Code:
[self dismissViewControllerAnimated: YES completion: nil];

I suggest you get a decent beginners book and go through it from front to back.
 
The only time you're using a Segue is when initially loading the "ViewController". The system is doing that for you, due to the setup of the project.

Here are your issues with the code.

First, ViewController.h needs to import the definition for your Windoww view controller.
Code:
#import "Windoww.h"

Second ViewController.m needs to instantiate your Windoww subclass of ViewController. The reason for the crash is because your call to return to the first view controller is calling a method, back:, that is only available in your subclass. Even though you are loading the right XIB file, you have not allocated the proper class for the new view controller, therefore the call is going to a declaration of the standard ViewController class. The proper line is;
Code:
UIViewController *viewController=[[Windoww alloc]initWithNibName:@"Windoww" bundle:nil];

Third, when trying to exit the "Window" screen, you are not using a navigation controller so are making the wrong the call. As I mentioned before you need to replace that line with the following.
Code:
[self dismissViewControllerAnimated: YES completion: nil];

I suggest you get a decent beginners book and go through it from front to back.

AHHH!!! I GOT IT NOW!

Thank you all so so so much for helping me!

THANKS!! I love this forum!
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.