Going from XIB to Storyboard

Discussion in 'iOS Programming' started by RipsMctits, Oct 24, 2014.

  1. RipsMctits macrumors regular

    Joined:
    Oct 19, 2011
    #1
    So I'm a noob trying to figure my way around iOS coding. I have most of the app in View Controllers already set up in my main storyboard, tied together with segues. I have buttons back and forth to most of the VCs in the main storyboard. In order to do some specific coding, I found it necessary to create a few separate XIBs. I have figured out how to go from my storyboard VC to the proper XIBs without a problem, but I've hit a snag with programming a "Back" button to get to the main storyboard VC that I'm coming from originally.

    Using the same code I used to go from the storyboard VC to the XIB doesn't work. The simulator logs the click, but instead of getting the VC I want, it just goes to a black screen. So now I'm stuck. Any help is appreciated.
     
  2. 1458279 Suspended

    1458279

    Joined:
    May 1, 2010
    Location:
    California
    #2
    Is there a way you can post the code? I'm no expert on storyboard, but I understand there's some aspects that are controlled in the settings.

    In other words, some things are controlled in sometimes convoluted settings and it's hard to post all the settings.

    On the other hand, I also understand that everything done in storyboard can be done in code.
     
  3. RipsMctits thread starter macrumors regular

    Joined:
    Oct 19, 2011
    #3
    Here is the code for the working buttons from the Storyboard VC:

    Code:
    - (IBAction)artbuttonpressed:(id)sender {
     
        NSLog(@"artclick");
        
        ArtViewController *artViewController = [[ArtViewController alloc] init];
        
        [self presentViewController:artViewController animated:YES completion:nil];
    And the same code used for the back button:

    Code:
    - (IBAction)backbuttonpressed:(id)sender {
        
        NSLog(@"backclick");
        
        WhatsNearby *whatsnearby = [[WhatsNearby alloc] init];
        
        [self presentViewController:whatsnearby animated:YES completion:nil];
    
    I have the proper .h files imported for the view controllers, just like with the working examples. The button press is logged, but instead of getting the WhatsNearby VC, I get a black screen.
     
  4. dejo, Oct 27, 2014
    Last edited: Oct 27, 2014

    dejo Moderator

    dejo

    Staff Member

    Joined:
    Sep 2, 2004
    Location:
    The Centennial State
    #4
    Normally, a back button should not present a view controller but, rather, dismiss it. You may want to consider using a UINavigationController which provides this functionality (via push/pop) for you.
     
  5. RipsMctits, Nov 5, 2014
    Last edited: Nov 5, 2014

    RipsMctits thread starter macrumors regular

    Joined:
    Oct 19, 2011
    #5
    Thanks for the input. I started over on the app and now I have my Navigation controller issues taken care of. The app looks much better. Now I have come to an issue that led me to all of this in the first place. It seems as though certain code that I try to do can only be executed properly when I build the view in a new XIB file. I know all about classes, defining actions and coding them in the .h and .m files, so I know the code is going to the right place.

    I'm trying to do a scrolling table view in one of my View Controllers on the storyboard. I've tried using a View Controller with a table view inside of it, as well as a straight-up Table View Controller. Neither of the methods I have tried worked properly. The basic template works fine, but the minute I try to do any coding with it I get shut out. I watched several YouTube tutorials, and both of the methods I have tried threw up errors and crashed the app on that View Controller.

    I had similar problems creating a scroll view. This is what let me to make my views in XIBs originally, as it seems the code works just fine with that method. But then I run into the problem of navigating from the XIB to a Storyboard, which is the topic of this thread. I cannot embed a Navigation Controller in the XIB and have it work properly in relation to the storyboard, so that throws up more problems (which is why I was making my own Back button in the original post).

    Most of these tutorials involve one or two View Controllers, and they're simple tutorials. Are there just some things you can only do from XIBs? Table Views, UIScrollView, nothing but problems. Everything else I do works fine, mainly just pushing views and redirecting to Safari, but still. If I can do everything in a Storyboard View Controller that I can do in a XIB view, it would make it a lot easier, but that doesn't seem to be the case. Am I wrong?

    I guess the short way of saying this, is

    1) Can I execute the same code in a Storyboard View Controller as I can in a XIB? Why do some things I try only seem to work if I have a separate XIB to design the view? (ex. UITableViewController UITableView)

    2) Is it possible to work with XIBs and Storyboards seamlessly? I had trouble using a Navigation Controller in the XIB while also using one on the Storyboard. Is there a correct way to do this?
     
  6. jgaz, Nov 5, 2014
    Last edited: Nov 5, 2014

    jgaz macrumors member

    jgaz

    Joined:
    Dec 30, 2007
    Location:
    Colorado
    #6
    It is hard to say without seeing your code what the problem is. If the tableView isn't working correctly don't forget that you need to a subclass of UITableViewContoller for each tableView you want to manage. Don't forget in the storyboard to make sure that your subclass is assigned as the controller for the tableView (you do this is the right hand panel - i think it is called the identity inspector).

    The subclass needs to conform to the UITableViewDataSource and UITableViewDelegate protocols in order for the tableView to work correctly.

    if you would rather use a xib you will need to use a delegate protocol to move from the storyboard view to your xib view.

    If you have all those in place you might need to post some code for more specifics or load it to github.
     
  7. PhoneyDeveloper macrumors 68030

    PhoneyDeveloper

    Joined:
    Sep 2, 2008
    #7
    Obviously one can do scrollviews and tableviews in storyboards. Is the tableview that you're talking about fullscreen or only part of the screen. I have plenty of tableviews that are controlled by UITableViewControllers in storyboards. It might be more complicated if the table view only takes up part of the screen.

    There should be little or no need for separate xibs these days.
     

Share This Page