Well I am a big noob with xcode, and I have a question. Well basically, I keep watching tuts, about creating a outlet with a web browser or a image view, and all you do is open up the editor and ctrl + click/drag the "image view or web browser" into "view controller H" but every time I open up the editor and click my image or web browser it just goes to in the editor "UIViewConroller.H" and doesnt stay on "ViewController.h". I dont understand why its doing this and every tut i watch or read about, they say do this, and it's not working for me.
So, in your XCode, I assume you have it setup where you have:
A storyboard
Some sort of ViewControllers inside the storyboard
Some ViewController classes
What you need to do, is you need to make sure that the correct class is referenced inside your specific view controller in the storyboard!
Then, you will want to make sure that you select the Venn Diagram up top, representing a split view.
And then you want to make sure your pair window is set to automatic:
Let me know if it helps! PM Me if not.
You need to select class for your ViewController.
Select the ViewController >Open Utilities > Identity Inspector and make sure that the Class is ViewController
I need help using Interface builder to create a storyboard and initial view, using xCode 6 and Swift. I do not want to start with the template "Single View Application" but with an "Empty Application" - for learning purposes.
I am starting with File->New->Application in xCode 6.
In the left pane I have selected iOS-> Application and I am choosing the template "Empty Application"
So now, I have my empty application and I want to use Interface Builder to create a story board.
I select File-New-File - then in the left pane I select iOS-User Interface and in the right pane I select Storyboard. I call my storyboard "Main"
That seems to do nothing, so then upon examining other templates, I decided that I need to go to info.plist and add a key/value pair, and so in info.plist I added a key "Main storyboard file base name" and a value of "Main"
After that I get the error:
Failed to instantiate the default view controller for UIMainStoryboardFile 'Main' - perhaps the designated entry point is not set?
So now I go to the story board and drag and drop a "View Controller" onto the storyboard, and btw - in the View controller inspector it is checked "initial scene - Is Initial View Controller"
But this doesn't create any swift file - which may be expected, but just to be clear it doesn't. Now when I try to run, I get the error:
Application windows are expected to have a root view controller at the end of application launch
So any ideas? I am trying to figure out how you properly use Interface Builder to create a storyboard and initial view and do a basic hello world, without skipping past the use of the tool to have it created for me in a template, because my assumption is you will quickly have more complex apps than can be created from a template, and it might be good to know how to use the tools - but I am not finding documentation on the subject.
Edit: strange timing I happened to find the answer just as someone else had also correctly answered the issue for me, so I will edit this post and remove the answer - as the answer below is exactly correct.
The storyboard automatically creates the window and instantiates the initial view controller for you. The code in the app delegate is creating another window which you don't want. You should delete all the code in didFinishLaunchingWithOptions, except for "return true". It will then run properly.
I am trying to create a new Swift project and am having some issues. I tried to create a new single page application but when I build I get an error saying:
2014-06-07 11:04:13.752 Matchismo (Swift)[2007:598021] Failed to instantiate
the default view controller for UIMainStoryboardFile 'Main' - perhaps the
designated entry point is not set?
But when I create the same single page application project with Objective-C as the language, it compiles and runs just fine. Is there some manual thing I must do in Swift to get a project up and running?
My understanding for this error is that I need the default view to be set, which is merely checking a box on your view controller's attributes (picture below). I tried the solution suggested in this stackoverflow post but it didnt help and I can't find much more help on the subject with Swift being so new. Any suggestions are appreciated.
Select the ViewController Scene. Now, select the inspector panel from the sidebar options. Check the “Is Initial View Controller” attribute option, save the project and build the project again.
Some times it doesn't take the initial view controller.Just create a new storyboard with anyname you want and set that name into the interface in your application setting.
Copy paste the code from previous storyboard and run the app.
The application will run fine.
Dont forget tocheck the initial scene in storyboard.
By following the below steps, it would work fine:
Select the Scene which is the type of ViewController/UICollectionViewController in Main.storyboard.
Select the Attribute Inspector in the right sidebar.
Click/Check the “Is Initial View Controller” attribute.
Re-Run of the project and this should solve the issue.
I just started learning XCode, objective-c, iOS, and all that. This is my first foray into app development. I'm not new to development, just iOS development and XCode.
So I'm going through a Udemy course that has me working with storyboards and I have some concern because every professional iOS developer I know uses something called Interface Builder which apparently removes the need for storyboards.
I've only just started, so I still have only a rough idea of what a storyboard even is....it seems to just be a graphical representation of a single page view. I don't know how it relates to this so-called Interface Builder and what their relationship is.
By going through this course learning with storyboards, am I being put on the wrong track? Or is this a useful beginning step before transitioning to the Interface Builder? Will using storyboards help me to work with that later? Am I wasting my time?
The Interface Builder refers to the part of Xcode that lets you view and edit Storyboards and .xib files (it automatically opens when you click on such a file).
A .xib (or 'nib') file is a representation of a single logical view in you application (on iOS, typically a UIViewController with a number of views, such as a UIScrollView and a UINavigationBar).
A storyboard is a collection of such views, and can be used to build transitions from views to other views, among other things.
I recommend reading Apple's Documentation on storyboards to get an idea of what they can do for you.
...
Interface Builder which apparently removes the need for storyboards.
...
Actually, storyboard is a concept within Interface Builder.
It's a visual representation of the entire app flow.
I think all you need is a quick-read through the Apple Interface Builder Doc.
In basic understanding, IB is a drag-drop area to visually create your views.
To quote:
You create your app’s user interface in Interface Builder. Select a
user interface file in the project navigator, and the file’s contents
open in Interface Builder in the editor area of the workspace window.
A user interface file has the filename extension .storyboard or .xib.
Logical Example: Instead of programmatically coding a UIButton and setting it's frame or constraints, you go to the Interface Builder, select a UIButton object and place it where you would want it to go. You will also specify what the object name and what method it responds to. (but this will need the object name and method name to be defined in the respective class's .m or .h file that the view is associated with)
Interface Builder can be either XIB/nib or Storyboard. Latter of which is the more recent (and recommended) method provided by Apple.
Using a storyboard, you have one single file, a .storyboard file that will represent the entire app flow.
An app can have multiple screens/views and so a storyboard will basically represent multiple UIViewControllers, each of which will be tied to a particular class.
For example, in this storyboard, you can visually see (assumptions from here on) that you have, say, 5 screens in the entire app:
Screen 1 begins with maybe a UINavigationController
Screen 2 is the root view of this UINavigationController, say, LoginVC (tied to LoginVC.m and LoginVC.h).
A button on LoginVC takes you to, say, SignUpVC (tied to SignUpVC.m and SignUpVC.h)
Another button on LoginVC takes you to, say, ProfileVC (tied to ProfileVC.m and ProfileVC.h)
Screen 3 is SignUpVC
A button takes you back to LoginVC
Screen 4 is ProfileVC
A button takes you to SettingsVC (tied to SettingsVC.m and SettingsVC.h)
A button logs you out and takes you back to LoginVC
Screen 5 is SettingsVC
Q.
By going through this course learning with storyboards, am I being put on the wrong track?
A.
No, absolutely not. You're going in the right direction.
However, i think knowing the former XIB/nib method is worth your time as well.
Plus, programmatically creating UIViews is highly recommended.
Q.
...is this a useful beginning step before transitioning to the Interface Builder?
A.
It's already getting you acquainted with the Interface Builder so there won't really be much "transitioning" required.
Q.
Will using storyboards help me to work with that later? Am I wasting my time?
A.
Yes, unless you work in a team under version control, in which case, XIB still looks good.
So what's XIB?
It's still within the Interface Builder scope...
Break a storyboard into it's individual views and you have multiple files (.xib files) that represent a UIView or UIViewController for a single class. (hence helps when you work in a team under version control)
So now... instead of having one .storyboard, you will have multiple .xib files that will be associated to all those classes that (you deem) needed a visual representation.
Links:
Storyboard
XIB
Storyboard :
Has a nice UI designer , WYSIWYG , drag, resize design editor, that generates code and sync with manual code changes.
SwiftUI:
Code is the single source of truth. No Designer. Lots of hard coding
I have a UIViewController I created in my apps storyboard, as well as a custom UIViewController subclass which I added to the project (and is correctly in the compile phase for my target). However when I go to set the 'Custom Class' property on the view-controller in Storyboard my custom class does not show up on the list.
Checked that the class is part of my app's target, not tests'
Double checked that it is correctly a subclass of UIViewController
Compiled program just to make sure xcode was working with latest information
Restarted xcode
What would cause my class to not show up in the 'Custom Class' drop down?
Two ways I found that solve the problem but they are work arounds:-
Just type the view controllers name in the text field, or
close the project and then reopen it and in the project initialization it places the file on the list.
If you still have your problem or for those who could have the same problem:
Make sure to select on your storyboard your "ViewController" instead of your "View" (which is automatically selected when you click on the view in the storyboard). The difference between those two is that when the view controller is selected, a blue rectangle pop up around your app. To be sure to select the view controller, open the document outline and select it directly in your storyboard hierarchy.
I would try the following:
Check that the file implementing the class is part of the build phases (check under target > build phases)
Add the .m file to build phases (if it isn't already).
Restart Xcode.
You can fix this by editing the XML of your Storyboard.
Right-click your My.storyboard entry in the Project Navigator panel and select the Open As->SourceCode menu choice. Find your view controller entry in the XML, and add the attribute customClass="MyController".
Save the storyboard.
Right-click your My.storyboard entry in the Project Navigator panel again, and select the Open As->Interface Builder - Storyboard menu choice.
The custom class entry will now contain your MyController class name.
Make sure your class inherits from UIViewController.
#interface ClassName : UIViewController
In Xcode 8, a few of my classes had the wrong path (case sensitive) specified for their file locations.
MyProject/mysubdirectory/MyViewController.xib (.m, .h)
vs:
MyProject/MySubdirectory/MyViewController.xib (.m, .h)
Really not sure how it ended up in that state, but my project exhibited the exact same behavior as above (no outlets/actions displaying in IB), and fixing that path fixed the problem.
I fixed this two different ways. One way was by I opened the .pbxproj file and fixing the case sensitive issue manually. The other way that worked was by tapping the folder icon under the Identity and Type section of the File Inspector tab of the file, and re-selecting the file there.
Click on a different view controller in the storyboard, then click on it's custom class pulldown to confirm the new class is listed, but don't select it. Click back on the new view controller you made and you should see it now listed in its custom class pulldown menu. odd, eh? just forces a refresh I think.
I had been having the same issues as described in this problem. However, none of the suggested answers fixed it for me. My project compiled OK without warnings or errors, but, in the .h file there were no 'outlet' indicators to indicate that my outlets had been linked to storyboard elements.
Additionally, attempts to create new outlets in my code, by right-click and dragging into my header file, were not recognising my header source as a potential target for this operation. And furthermore, my Class did not make an appearance in the Custom-Class dropdown for the ViewController's property inspector panel.
And yet, the project compiled OK.
Closer examination showed that I had defined my own class in the following manner...
#interface KJBMainDataViewTrackConMk2<UIScrollViewDelegate> : UIViewController
which apparently compiles nicely.
But, if this is changed to the following, (moving the protocols to the end)...
#interface KJBMainDataViewTrackConMk2 : UIViewController<UIScrollViewDelegate>
Then everything springs to life. All outlets are suddenly indicated as being 'connected' with a storyboard element. And right-click dragging starts to work again, and my custom class appears in the custom-class drop-down in the property inspector panel for the storyboard ViewController!
Other answers here probably represent the most likely causes of this condition, but, I felt it worth mentioning at least this one other potential cause.
I had the same problem, but none of the other solutions worked for me. The issue for me was that I had a Mac and iOS target, both with their own versions of the same view controller. For example, I had a .h/.m pair of files named FooViewController for Mac and another .h/.m pair of files named FooViewController for iOS. Each pair was properly included with their respective targets, but for some reason Xcode does not like it and my view controller would not show up in the Custom Class dropdown in the view controller in the storyboard. I ended up renaming my class in the iOS view controller and it immediately showed up in the dropdown.
In my case, I drag a new TableViewController object to the storyboard, but I add a new file which's subclass is "UIViewController".... Then, I add a file which's subclass is "UITableViewController", problem solved!!
For those of you who are still having this problem after trying all the way around is probably because you clicked the View instead of ViewController.
You have to choose the file when ViewController is clicked.
This solved my problem.
I happened to come across this problem, and had no luck after trying the previous suggestions. Finally I found the reason is the header file's type is set to C++ header. After changing it to C header (like all the other header files), the class appears in the drop list. Don't know why though... Possibly helpful for others so I post it here.
Storyboard is looking for the custom class but physically its no there and its not displaying the custom class name in the list and also not displaying the outlets . Following solution perfectly worked for me.
Just copy your code some where else.(Lets say on desktop)
Open your existing code.
Delete the custom class file.(Move to trash)
Now add files from copied project folder (From desktop)
Don't forget to check "Copy if needed" check box
Open the story board and bingo you will get your custom class files in dropdown
be sure initially not adding the CustomViewController to any group or folder. place it in the root of your app.
none of the above(or below :) helped me. though I found that
after adding new viewcontroller to storyboard (just by dragging it in)
and adding my class by File\New\File\Objective-C Class, give it a name, no XIB, Next, Create
if I select my viewcontroller in storyboard and try to assign my class to it - my class is not there
BUT
if I click on a view that is in the viewcontroller itself then click on a class dropdown menu in Custom Class
AND THEN
select viewcontroller (click on a bar below the viewcontroller) and now again click on a class dropdown in Custom Class my newly added class magically shows up.
weird, must be a bug with refreshing. Xcode Version 5.1 (5B130a)
Make sure you select View Controller to which you want to attach your class. The easy way is open Document Outline and choose your view controller (When you tap on it form the Storyboard sometimes it simply doesn't choose the object you meant).
for my case, somehow bundle resources got deleted, so I added back and worked!
Build Phases -> Add Build Phase -> Copy Bundle Resources
find your file
Then drag and drop your file there
Then make sure your target membership is checked.
In my case, I selected the wrong UI.. so I deleted the class file and created a new one and selected the correct parent class
I had to restart XCode 7.3 (7D175)
What worked for me was, click on the file in the Project Navigator, then, in the File Inspector under "Identity and Type" beneath the "Location" dropdown box, click on the little folder icon and then select the file in the popup window.
Try to clean your project, and also restart your Mac. One peculiar thing that I did was change all the Custom Classes names and build the project again. It worked!
For macOS projects, creating a new class generated a class inheriting from NSObject instead on NSViewController.
Change from
import Cocoa
class AppsViewController: NSObject {
}
to
import Cocoa
class AppsViewController: NSViewController {
}
I was fairly frustrated with this issue as none of the answers above had solved my problem.
In my case: I was in the middle of working on swift view controller file and was making active changes (such as creating a custom collection cell class). I had not finished the code block and left it open like so :
class tableViewCell: UITableViewCell {
}
class collectionCell:
class viewController: UIViewController {
override func viewDidLoad(){
super.viewDidload()
}
}
Note the incomplete code block 'collectionCell2'
This was enough for xcode to not recognize my viewController file as such.
Once I completed this block the file reappeared in my xcode as an option.
Very silly and simple.
Make sure the view controller is matching with the same Type in the storyboard .
In my case swift file name was different then swift class name i.e
file name was ViewControllerTest.swift
and class name was ViewController.swift
after changing both to common name solved my problem
Restart Xcode after above changes
Make sure the class name of the ViewController is the name that you want. i.e.
class MyCustomNameViewController: UIViewController {
.
.
}
Changing just the filename is not enough.