Best way to set-up an iPhone project? - iphone

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.

Related

Extending the Eclipse PropertiesView with further tabs for existing PropertySources

After a quite long struggle with the known and unfortunately one of the few help articles about controlling properties, tabbed properties etc. (links below), I have decided to ask for your help.
What I need to do seems not that hard, but, well, I just couldn't bring the pieces together. So the problem is:
I want to extend the existing properties view of Eclipse (PropertySheet) with some further tabs, which will be later on filled with certain information from EMF objects, which in the end implement IAdaptable. So they can be queried for PropertySources and there are already a few tabs, sections extended in the corresponding project in its manifest, which are being successfully gathered from the Selection Listener of the PropertiesView.
Here comes the tricky part: I don't need to extend this project further, by defining further tabbed properties in its manifest. I need to implement a seperate plug-in project, which does this extension job for the other main project. I don't need extra views or so. This existing project provides the property sources and like sad has its own designed tabbed property view via its extensions.
I have actually become quite familiar with the concept of the views and properties, I can build some Property Sources and let the Properties View gather/show/manipulate the properties.
But this idea, letting an external plug-in extend the Properties View with tabs of an another EMF-based plug-in project, just can't get to me. I am really confused and don't know with what to begin with.
I would be unbelievably glad, if you could point me to the right direction.
Thanks a lot!
*Links:
http://www.eclipse.org/articles/Article-Properties-View/properties-view.html
http://www.eclipse.org/articles/Article-Tabbed-Properties/tabbed_properties_view.html

Unknown class in Interface Builder file

Why am I still getting this error when I run my iPhone app? The file is a ViewController that I have been working to delete and replace, but it just won't die. As far as I know, I don't have any reference (string or otherwise) to this file in my project.
I have deleted the related file (I'm trying to get rid of it.)
I have cleaned the project and rebuilt.
I have "Reset Content and Settings" in my simulator.
I have done a grep (grep -i -r "TheClassName" *) and nothing matches except my UserInterfaceState.xcuserstate file.
I have searched the code using XCode's Find/Replace tab.
I have double checked my Build Phases and am pretty sure it isn't in there (its a large project).
Any other ideas? I've spent way too many hours trying to figure this simple thing out; I must be missing something.
Thanks!
Check your nibs or storyboard, and make sure none of your views are set to the class!
I finally fixed the problem after trying it on multiple machines over the course of almost 2 days! I will not be thwarted!
I tracked the problem down to a call to setViewControllers on a UINavigationController which is called on initialization of the application. I was always being passed 3 objects (there are 3 panes in the navigation controller). Even though I had deleted the third object, as previously explained, three objects would always be passed in. The class type of the first two was correct, but the third would just be a UIViewController. Curiously, this view controller had a nibName which corresponded to the object file and Xib file that I had previously deleted. Of course, when view was called on this borked UIViewController, it would crash since the corresponding nib had obviously been deleted. Remember, the textual name of this object or Xib could not be found in my directory with grep, so I have absolutely no idea how in the world it came into existence when I ran my app.
So, I figured the app may not have been cleaned properly. I double and triple checked this. I even validated that my Workspace settings were correct (File->Project Settings->Advanced). The app was indeed being recompiled fresh every time.
Secondly, I started thinking that perhaps the object was being set by some other means. Working backwards, I added some breakpoints and found out that initWithCoder was being called on the parent UINavigationController--this was eventually working down to call the setViewControllers on the object and assigning the three view controllers (one of which was the offending one). I could easily see from the call stack that the Nib file that was being loaded was deserializing something offensive.
So, I started digging into my Xib file. Of course, the object name wasn't in the file (as expected since the grep didn't find anything). I deleted and recreated the portion of the Xib that included my root UINavigationController. This ended up changing the Object ID and ref within the Xib file.
Secondly, I created a new Xib and UIViewController with the same names as the one which I had previously deleted, hoping that Xcode might be happy if I created and then re-deleted them. I then compiled, re-deleted them, updated by Xib file yet again, reverified with grep that yes, indeed, nothing existed with that name.
And it worked. After spending multiple days on this issues, I'm fairly sure that there is a bug here in the interface builder, but do I want to revisit this problem to file a bug report? Absolutely not...
In my case, I solved an issue by name of Custom class name of View instead of Custom class of ViewController. By mistake i added like this for view as shown below.
It Should be for ViewController like this.
This is in my case, for you may be it's related with another component.
This happens when the view class is in a framework. Select the framework's module. Example with a CocoaPod: HSegmentControl.
Make sure when you add or rename or move files around especially in folders, that when you add them you:
A. Create Groups, not references they don't usually read in.
B. Check the boxes for the apporpriate "Product(s) or Target(s)" you want to add the source to.
Another thing to try :
I had to toggle "Inherit from Target" under the "Module" control of "Custom Class."

Xcode iPhone: New Project Template, Combine?

This question is simple... you have a choice of which Template you'd like to use when creating a new iPhone application in Xcode.
What if I choose a View-Based, but I need a Navigation-Based application too? Can you combine the various templates within a project? I mean, is it just a matter of creating a new .xib file and dragging on the various UI components?
The navigation based template is also view based. Look at the code, the navigation based template contains a rootViewController which loads its view from a xib file.
You cannot combine templates automatically you'll have to do it yourself.
You can always create custom templates as you want. You just need to pick a template from Xcode then you can modify it as you want and just place it on a proper location.
Read my this blog post for a better understanding - http://www.makebetterthings.com/blogs/iphone/how-to-create-xcode-project-templates/

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

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.

Iphone sdk - How to setup a 'template'

I've been working on a Cook Book App and I've been making each page individually which takes a really long time to do, I asked a question similar to this and it was brought to my attention that you can setup a way to automate the design process so all you need to do is input your data.
Can someone please explain in as much detail as possible how you setup your xcode files/code to automate such a process
So for example I would just enter the page text and it would automatically put my standard background picture in and add a scroll view and appropriate buttons etc.
Thanks
You could make one master view that contains all the controls that you need: standard background picture, scroll view, appropriate buttons, etc, and make any subsequent views that you create inherit from this view, so that they all contain those controls.
You could also use just one view and work with multiple instances of it, one instance per page. Just make sure to have a Text property on it, or a constructor that takes in your text string, so that you could set it to a different text on each page.
Xcode project templates and file templates are pretty easy to make, with a few caveats.
Check the answers to these questions:
Add new templates in Xcode
Change templates in XCode
Also take a gander at these handy tutorials:
Custom Xcode Templates
Xcode: How to customize the existing project templates
It sounds to me like your putting your data into your views (pages). That's a big design error. You need to employ the Model-View-Controller design pattern and separate your data from your views. That will make it easy to create one view (template) that you can reload with data to display each individual recipe.
The first thing to do is to separate your data from the view. You need to have the recipes stored in an array, dictionary, Core Data etc and then wrap that data in a dedicated object. The second thing to do is to create a dedicated view to display all the recipes. As the user moves from recipe to recipe the app will simply remove and add information to the same view as needed.
I would recommend Cocoa Recipes for Mac OS X: The Vermont Recipes, Second Edition because it addresses these issues and it uses a recipe type app as its example. It's for Cocoa but the basic principles apply to iPhone apps as well.