iOS project not showing Interface elements built from Interface Builder in my view - iphone

I am working on a project which includes many UI components on one view(being built in Interface Builder). I have found that after saving and moving my project directory, the interface which should include all of these elements, is empty(there are no visible UI components in the view).
There are actually 2 projects. 1 is a framework project, the other is the iphone project which i build & run on the device - everything is contained within a folder which i may move frequently as other members in my team work on it.
the view which is not properly showing elements, is an XIB file which can be modified through either the iphone project or framework project.
Why is this happening and how can i troubleshoot this problem further? I am not sure how to fix it.

Many components will not show if they're not been connected to a property, and some will not show if their datasource or delegate is not connected.
Have you wired everything up, making all of your connections?

Could you check the view hierarchy in the -(void)viewDidLoad ? As Matthew said, if those components are not connected to properties, they won't be shown. And, if they are not add onto proper view, then they won't be shown too.
You can check the view hierarchy of viewController by browsing the property subViews of self.view.

Related

Why aren't my custom classes appearing in the dropdown in Interface Builder?

I am using Interface Builder and Storyboards to build my app. I am trying to connect my source code to my UIViewController in Storyboard, but none of my classes show up in the Custom Class dropdown menu. This is occurring in Xcode 11 beta 2 and Xcode 11 beta 4.
I've tried some solutions in this Stack Overflow answer, but they are not working. I've already done all of the following:
Relaunched Xcode
Deleted derived data
Reinstalled Xcode
Tried a different Storyboard
Recreated the UIViewController file
Made a new project (the problem even occurred there)
Typing the UIViewController name into the dropdown menu text field
None of the solutions worked and I have made sure that I was connected a UIViewController to the Storyboard not something else like a UIView. This is occurring with all of my UIViewControllers and UITableViewControllers.
(I wish I could show an image but I do not have enough reputation...)
I expected the UIViewControllers that I have created to appear in the custom class dropdown. I also surprised to find out that manually typing the view controller into the text field does not work. Instead, when I run the project, I just get this message in the console:
Unknown class ViewControllerName in Interface Builder file.
It appears that your classes aren't added to the project target. Try this:
1) Make sure your classes are added to the right target membership on the Inspectors Panel on the right:
2) Make sure the class inherits the View Controller type:
class CustomViewController: UIViewController
3) Reload xCode and check if the class is enabled:
It happened to me and I've noticed the Class dropdown was showing classes from another project that I have opened in the background. After closing all the other projects, the drop down finally showing the correct list of classes from the project that I'm working on. Seems like an Xcode storyboard editor bug.

How to add a downloaded widget to the Objects box in Xcode

I'm writing my first iPhone app. I needed a custom switch (I want it to say "Male/Female" rather than "On/Off"), and I found RCSwitch but I'm having trouble figuring out how to integrate a downloaded widget into my project. I assume this is a fairly common thing to do, but I can't seem to find any documentation online on how to use a downloaded widget / class.
I have succeeded in adding the code in via Build Phases -> Link Binary with Libraries. An RCSwitch directory appears within my project tree, and if I do a diff I see that it has added code related to RCSwitch to the header files.
The problem is getting the widget onto the .storyboard image. The RCSwitch widget itself does not appear in the "Objects" box -- the one that is by default at the lower right of the screen and includes images of the widgets that you can drag into the storyboard. Perhaps I'm missing something?
from the xcode 4 transition guide (pg. 65):
Drag a custom view object from the library into the nib file.
After adding the custom view to your nib, select the custom view and
assign the correct class to it in the class field under Custom Class
in the Identity inspector
Some more resources:
iphone-creating-custom-objects-for-interface-builder
Interface Builder Help - Custom Object

iPhone Beginner Question - Hooking Up Actions

I'm just starting out with iPhone development, and in my hello world application I'm having a hard time hooking up a view to a controller with actions. I followed the instructions in the book I'm reading (I believe), but depending on where I run the application the app behaves differently.
-When i command-r from the code, I see only the single button I have on the view taking up the whole window. When I click the button the action is triggered.
-when I command-r from the interface designer I see the button, label, and textbox lined up correctly. When I click the button nothing happens.
Anyone know why this is happening/how to fix it? Thanks.
Launching simulator from interface builder only simulates selected .xib file. You should only do that to test your view design.
If you want to learn the basics about iPhone development I recommend:
NewBoston: http://www.thenewboston.com/?cat=34&pOpen=tutorial
Stanford: http://itunes.stanford.edu/
both are free video tutorials on how to make iPhone apps.
Good luck!
you accidentally the whole view.
Seriously. You made one wrong connection. You connected the view outlet of the viewController (aka File's Owner) with the UIButton.
just delete this connection and connect the view outlet of the File Owner with the "Root"View.
And you should probably remove almost all connections that trigger btnClicked: too. TouchUpInside from the button is enough.
And you should follow the objective-c coding style (Part II) and start all Class names with a capital letter. chapter_2ViewController should be something like Chapter2ViewController.
To my knowledge you cannot run an app from interface builder, I may be mistaken.
You should make sure your interface builder file is saved and run the app from within xcode
just a guess, but is the window size in the simulator different than that in IB? You might check the control resizing masks and on the sizing tab in IB.

Best way to set-up an iPhone project?

Looking for the best way to set-up an iPhone project in XCode ... namely:
What is the preferred project template to start with (e.g View-Based or Windows-Based application)?
What folder structure should I create in XCode to manage the project? For example, under "Classes" is it a preferred practice to add Models, Views and Controllers sub-folders?
Any other best practices, tips, etc... would be appreciated.
Thanks
Take the most "complicated" template, based on your level of knowledge. I usually start out with the "Window-based application" myself, and add components one at a time from there.
I keep all of my code (.m/.h/.c/etc) in the "Classes" folder and only rarely add subdirectories to it. One exception is a "Generated" subdirectory for classes generated from Core Data entities.
When I create a new UIViewController subclass, I rename the resulting .xib to remove the "Controller" part; i.e. MyViewController.m gets paired with MyView.xib. (I think MyViewController.xib reads funny, as the xib isn't for the controller, it's for the view.) I also move the .xibs into their own directory next to the project file to keep things tidy.
There is no "best" template. Window-based is the most basic, while View-based starts you out with a view and a view controller.
I'm with Shaggy Frog on renaming xib files to not have "controller" in the name. However, I like to create groups to logically separate functionality, and in those groups I place view controller code along with the xib files those view controllers use. Then you know what belongs with what.
I also like a create a top-level "Application" group into which I put the app delegate, main xib file (if any), pch file, info.plist, app icon, Default.png and other things related just to the application so they are all easy to find - after you add a number of files each of those things can get lost in giant lists of stuff.
Basically organize things so you can find them, a structure that makes sense to you might not to someone else.
Window-based provides you with the most flexibility, and is probably what you want to choose after you've got a couple of projects under your belt. I find with the other templates that I'm usually removing too much code, and it would be quicker to just start from scratch.
I usually setup my projects by creating 4 subfolders under Classes: "Views", "View Controllers", "Model Objects" and "Helpers". Model objects contains all the basic object types, where as Helpers contains things like utility classes or similar. Sometimes, where relevant, I will also create a Table Cells folder underneath both Views and View Controllers. I move MainWindow.xib to the Views folder.
If the project is large, I will sometimes also have sub-folders for the Views and View Controllers based on the UITabBarController tabs. So if I have 5 tabs, then the Views folder will have 5 sub-folders, as will the View Controllers folder. I find this helps to keep everything logically together in the same place.
One other thing I do is create an Images folder under Resources, otherwise that folder gets way too cluttered very quickly.

Recreating a Duplicate iPhone Project with Interface Builder Errors

Due to some extraneous errors in a previous XCode project that wouldn't allow my iPhone app to run on the iPhone, I had to take all the code and files from what we'll call Project1 and build a new project called Project2.
I then filled Project2 with all the same files, not changing any code.
Next I had to recreate the Interface Builder files. As far as I can tell, this was done with the exact same classes declared in all the IB objects.
However, when I build Project2, it only shows a visible black screen and doesn't display the app.
The one difference I have found between the two projects is that in Project2's Interface Builder, the ToolbarController outlet is not even available for the view, and it is in Project1. I am assuming the lack of connecting the File View to ToolbarController is the problem.
Why is ToolbarController (as shown below) not available and how do I fix this difference?
Below are two screenshots. The first is Project1 and the second is Project2. :
alt text http://img32.imageshack.us/img32/8296/picture1xne.png
alt text http://img51.imageshack.us/img51/4194/picture3to.png
You've probably got the "File Owner" (or the "Toolbar View") set to the wrong class. Interface Builder doesn't see any outlets or actions in the classes you have set currently.