Xcode: Can segue from storyboard to xcode but not opposite?

Discussion in 'iOS Programming' started by nichlaspro, Jan 21, 2015.

  1. nichlaspro macrumors member

    Joined:
    Jan 21, 2015
    #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 :)
     
  2. PhoneyDeveloper macrumors 68040

    PhoneyDeveloper

    Joined:
    Sep 2, 2008
    #2
    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.
     
  3. nichlaspro thread starter macrumors member

    Joined:
    Jan 21, 2015
    #3
    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!
     
  4. DannyBres macrumors 65816

    DannyBres

    Joined:
    Oct 30, 2007
    Location:
    UK
    #4
  5. nichlaspro thread starter macrumors member

    Joined:
    Jan 21, 2015
    #5
  6. DannyBres macrumors 65816

    DannyBres

    Joined:
    Oct 30, 2007
    Location:
    UK
    #6
    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).
     
  7. nichlaspro thread starter macrumors member

    Joined:
    Jan 21, 2015
    #7
    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! :)
     
  8. nichlaspro, Jan 22, 2015
    Last edited by a moderator: Jan 23, 2015

    nichlaspro thread starter macrumors member

    Joined:
    Jan 21, 2015
    #8
    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!!!
     
  9. PhoneyDeveloper macrumors 68040

    PhoneyDeveloper

    Joined:
    Sep 2, 2008
    #9
    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.
     
  10. nichlaspro, Jan 23, 2015
    Last edited: Jan 24, 2015

    nichlaspro thread starter macrumors member

    Joined:
    Jan 21, 2015
    #10
    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!
     
  11. xStep macrumors 68000

    Joined:
    Jan 28, 2003
    Location:
    Less lost in L.A.
    #11
    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];
     
  12. nichlaspro thread starter macrumors member

    Joined:
    Jan 21, 2015
    #12

    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!
     
  13. xStep macrumors 68000

    Joined:
    Jan 28, 2003
    Location:
    Less lost in L.A.
    #13
    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.
     
  14. nichlaspro thread starter macrumors member

    Joined:
    Jan 21, 2015
    #14
    I have updated the link, it should work be the project folder now..Just right click and download;-)

    Thanks!
     
  15. xStep macrumors 68000

    Joined:
    Jan 28, 2003
    Location:
    Less lost in L.A.
    #15
    No. That isn't what I'm seeing. I only see the project folder.
     
  16. nichlaspro thread starter macrumors member

    Joined:
    Jan 21, 2015
    #16
    So, does it work now? Have compressed it into zip as u said...
     
  17. xStep macrumors 68000

    Joined:
    Jan 28, 2003
    Location:
    Less lost in L.A.
    #17
    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.
     
  18. nichlaspro thread starter macrumors member

    Joined:
    Jan 21, 2015
    #18
    AHHH!!! I GOT IT NOW!

    Thank you all so so so much for helping me!

    THANKS!! I love this forum!
     

Share This Page