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

RipsMctits

macrumors regular
Original poster
Oct 19, 2011
125
24
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.
 

1458279

Suspended
May 1, 2010
1,601
1,521
California
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.
 

RipsMctits

macrumors regular
Original poster
Oct 19, 2011
125
24
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.
 

dejo

Moderator emeritus
Sep 2, 2004
15,982
452
The Centennial State
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.
 
Last edited:

RipsMctits

macrumors regular
Original poster
Oct 19, 2011
125
24
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?
 
Last edited:

jgaz

macrumors member
Dec 30, 2007
34
4
Colorado
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.
 
Last edited:

PhoneyDeveloper

macrumors 68040
Sep 2, 2008
3,114
93
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.
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.