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.
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 ?
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.
Ran into the same issue and restarting XCode was no help. You can always right click the storyboard and select Open As > Source Code. Find your view controller element in the XML file and add a customClass attribute:
<viewController title="Login" id="TJH-Bg-q4u" customClass="XYZLoginViewController" sceneMemberID="viewController">
...
</viewController>
Manual override FTW :).
Check your project settings. xcode->targets->build phases->compile sources
your viewcontroller's implemantation file must be added to this list.
For this to work you have to make sure of the following:
1) The element added to the storyboard is an UIViewController
2) The class you defined has the UIViewController as its superclass
#interface MapShownViewController : UIViewController
3) The Class is being correctly built in the project.
I've been running into this issue and tried all other solutions posted here.
The thing that worked for me was to set the correct super class after creating a custom class. Then you should be able to find and select it from the class dropdown.
e.g.
class LabsViewController: UITableViewController {
Check if you did choose the correct super class in your new class. Sometimes you create a view controller inherited by a UITableVIewController. This one can't be applied to a ViewController pattern in the Storyboard.
I had to set my custom class which inherit from UIViewController and act as table view controller to UITableViewController. I made simple trick and just changed my custom class inheritance to ": UITableViewController" and then i can set this class freely to controller. Of course after it was set i changed inheritance back.
I had the same issue with Xcode 7.1.1 on a Mac OSX app. I tried all the suggestions from the other answers – no success.
Finally I deleted my view controller files and created brand new ones.
Then it suddenly worked...
Just adding another possible solution that helped solve my problem since the others didn't.
I noticed that searching for my custom View Controller file using Command+Shift+O it was being found, but I couldn't see in which folder the file was, so I noticed that for some reason my custom class was missing from the project but still being found in the search.
All I had to do was to move the files to the project again and Voila!
Hope this can help someone in the future.
Related
I am trying to manually start a view controller using storyboards.
That is written in code as opposed to wiring it up. I tried:
self initWithNibName:(NSString *) bundle:(NSBundle *)
but I am not sure if they are classed as nibs or what they are classed as in storyboards. Any help would be great thanks!
Sounds like you are looking for this method:
AlertContainerViewController *alertContainerViewController =
[[UIStoryboard storyboardWithName:#"MainStoryboard_iPhone" bundle:NULL]
instantiateViewControllerWithIdentifier:#"alertContainer"];
You need to give the ViewController object in the Storyboard a unique identifier and specify the subclass. You do both through the Property Inspector.
I have a question about using Xcode storyboard in the PhoneGap 1.7 project.
I have created an empty PG project, added a storyboard file to the project and dragged a View Controller onto the storyboard. But I do not find the wayto bind this controller to the variable created by PhoneGap framework:
CDVViewController* viewController;
How do I bind it if I can?
Thanks in advance.
Make sure you bind the ViewController in InterfaceBuilder to the CDVViewController class or your own subclass. It might also be useful to add a webview in the IB and bind it to the CDVCordovaView of the above view controller.
One thing you need to take care of is the fact that the CDVViewController does not implement the initWithCoder: method (as of Cordova 2.2.0), which is required for Storyboard usage. Add the following method to CDVViewController, so your view controller get's correctly initialized when instantiated from Storyboards:
- (id)initWithCoder:(NSCoder *)aDecoder
{
self = [super initWithCoder:aDecoder];
if (self) {
[self __init];
}
return self;
}
I want to use the following transition cross dissolve, but I do not want it to appear flicker when Transition
I apologize I have weak English language
You need to add a subclass to your project:
Add a new .h and .m file as a subclass of UIStoryboardSegue
Add this code to your .m file:
- (void)perform {
[self.sourceViewController presentModalViewController:self.destinationViewController
animated:NO];
}
Now go to your .storyboard and add the name of your .m file to the
class field of your prefered segue.
I can't find the storyboard's segue's class field in XCode 4.4.1. Is it possible that the field was in previous versions but not in the current?
EDIT: I found the way. You must select 'custom' when creating the segue and it works.
Thanks.
BTW: The tutorial is not available.
I have a existing iPhone application created using traditional nib interface files. Now I am going to convert the application into iOS5 story board style interfaces. I have changed almost all interface files and working fine.
But I am comeup with small issue. My Exsiting application have a code for presentModalViewController:animated: without animation. That's by setting NO to animated property. I have a problem with doing the same with segues. I can't find any attribute to disable animations in segues.
I resolve above issue using custom segue. I created custom segue by extending UIStoryboardSegue class and added code to presentModalViewController without animating. Here's the solution to above question.
#import "ModalViewWithoutAnimation.h"
#implementation ModalViewWithoutAnimation
- (void)perform {
[self.sourceViewController presentModalViewController:self.destinationViewController animated:NO];
}
#end
Thanks
I am writing a library to be used by developers for the iPhone (similar to the way that OpenFeint is implemented) and I am trying to create a ViewController with an associated XIB so that I can instantiate it in my code with
SplashScreenViewController *splashScreenViewController = [[SplashScreenViewController alloc] init];
UIWindow *topApplicationWindow = [self getTopWindow];
[topApplicationWindow addSubview:splashScreenViewController.view];
However, while this works with simple controls (UIButtons, etc), nothing shows up with my SplashScreenViewController. SplashScreenViewController is very simple:
#import <UIKit/UIKit.h>
#import <Foundation/Foundation.h>
#interface SplashScreenView : UIViewController {
}
#end
and the implementation is empty. In my View XIB (SplashScreenView.xib), I have tried setting the File's Owner's class to SplashScreenViewController which didn't work, then I tried it the way I've seen it done in OpenFeint which is to add a View Controller in IB and make the main UIView a child of it and make it of class SplashScreenViewController instead. That also does not work (does not display).
I'm wondering if anyone has a good idea for what I might be missing, or if someone can recommend a walkthrough for creating new ViewControllers the way that I'm attempting to.
Thanks!
Try 2 things :
Call initWithNibName not just init. Maybe the OpenFeint you were talking about were overriding the init to call initWithNibName , that's why you don't see it.
Set SplashScreenViewController as your file owner, and connect his view outlet to your
view in IB.
Hope it helps.
Instead of [splashScreenViewController alloc], try [SplashScreenViewController alloc]. I'm surprised you didn't get a compiler warning.