Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

IB - Can't assign class for a View Controller

I'm quite new to IOS developpement, and I'm facing a problem here that I haven't encountered before. Here's what I have :

I created a project, added some ViewControllers attached to their own classes. But now, I just added a new ViewController in the storyboard. Then I created a new Objective-C class (with is a subclass of UIViewController). The problem is that in IB, I can't link the ViewController to the newly created class, as I simply don't have the class in the list provided by IB (see the image below). My new class is called MapShownViewController, but as you can see on the image, it's not available.

enter image description here

It worked well for all my other classes but not for this one.

Here's the MapShownViewController.h :

#import <UIKit/UIKit.h>

@interface MapShownViewController : UIViewController

@end

And the MapShownViewController.m :

#import "MapShownViewController.h"

@interface MapShownViewController ()

@end

@implementation MapShownViewController

- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
    self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
    if (self) {
    }
    return self;
}

- (void)viewDidLoad
{
    [super viewDidLoad];
}

- (void)viewDidUnload
{
    [super viewDidUnload];
}

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
    return (interfaceOrientation == UIInterfaceOrientationPortrait);
}

@end

Can someone explain me what I made wrong please ?

like image 608
B F Avatar asked Aug 14 '12 10:08

B F


People also ask

How do I change the class of a view controller?

If you want to change a view controller to a different class you have to both change the class in your source file and then select the view controller in Interface Builder's "Identity inspector" and change it's class there as well.

How do you instantiate a view controller in storyboard?

In the Storyboard, select the view controller that you want to instantiate in code. Make sure the yellow circle is highlighted, and click on the Identity Inspector. Set the custom class as well as the field called "Storyboard ID". You can use the class name as the Storyboard ID.

How do I segue to another view controller?

So, Ctrl+Drag from the “Go to Other View Controller” button, to somewhere in the second View Controller. It can be anywhere in the main box of the second view controller. When you release, it will show you a box like the one below. This lets you set what kind of segue you want to use.

How do I add a view controller to my navigation controller?

Step 1: Embed root view controller inside a navigation controller. In your storyboard, select the initial view controller in your hierarchy. With this view controller selected, choose the menu item Editor -> Embed In -> Navigation Controller .


1 Answers

I had this exact problem and it drove me mad. I first noticed it after upgrading XCode to 4.4 from 4.1. I had an existing project that I had been working on in the older version of XCode, and I continued to work on it in 4.4. I did exactly what you did and created a new View in the story board and then created the sub-class files, but the class just was not avaiable in the Custom Class dropdown in IB. After much Googling and frustration I resorted to Quit Xcode (complete quit, not just close) and then re-start it. Then as if by magic it all started working and the new class was immediatley available in the IB custom class dropdown.

like image 149
ross_t Avatar answered Sep 21 '22 12:09

ross_t