iphone uitableview - linking problems? - iphone

I am trying to follow a tutorial about xml parsing http://www.edumobile.org/iphone/iphone-programming-tutorials/parsing-an-xml-file/ . The tutorial does not explain how to link and that is the part that i am stuck on. Looking at the source code provided i can see that "view" is linked with "file owner". In MY file, when i do this, i cannot link them. It does not highlight. Does anyone know why? what are the usual causes for this? (new to iphone). Thanks for any help!

You will find this helpful http://mobiforge.com/developing/story/iphone-programming-fundamentals-outlets-and-actions
This one is specific to XCode4 but is also helpful to understand the Interface Builder basics
http://developer.apple.com/library/ios/#documentation/iphone/conceptual/iPhone101/Articles/04_InspectingNib.html
If you add a new file (a subclass of view controller) you will get three files .h,.m and .xib. The File owner is always connected to the correct View Controller which happens to the owner of this nib(.xib) file. you can verify the same as shown in image below.
If this is the case then I am sure you can always link up your new elements (labels,buttons) to the correct Outlet. Just a reminder here that the declaration should start with the keyword IBOutlet so that It shows up in the interface builder.
eq IBOutlet UILabel *lblTitle;

Related

This class is not key value coding-compliant swift

Yes, there are several posts about this problem, but none of these seem to answer my problem?
I created a custom view in a nib file and connected it to code, exactly like here:
Link
Only differences:
My class is named EditorSectionView not CustomView
My outlet's name is customView, not contentView
Apart from the code, i did the following, as described in the gist:
In Interface-Builder, click on "File's Owner" and make the File owner's custom class "EditorSectionView", NOT the View itself
Drag and Drop the top level view (the "Custom view" named item from Interface Builder) to the EditorSectionView via Assistance Editor to create an outlet named customView.
Whenever i start the app and click on the button that should use this custom view, it crashes with the error:
"This class is not key value coding-compliant for the key customView".
However, when i have a look at the connections inspector, in my nib file, there is no "!" like some other posts pointed out and all seems to be fine.
I am using the nib file like that to instantiate it:
form +++ Section(field.name) {
let header = HeaderFooterView<EditorSectionView>(.nibFile(name: "EditorSectionView", bundle: nil))
}
This should create a new form section in Eureka, as described here: https://github.com/xmartlabs/Eureka/blob/master/README.md (Search for "You can use a Custom View from a .xib file:" in the readme).
I have tried to solve this for an hour now, but i don't know what else to do. All connections are set (the outlet, the class for the UI), the code itself copied from a gist, etc.
What am i doing wrong here?
Thanks.
EDIT:
If i set the custom class in the identity inspector as well to EditorSectionView, not only the File's Owner custom class to EditorSectionView, it doesn'T crash any more with "not coding compliant for key XY" but it crashes with EXC_BAD_ACCESS on the line i am calling loadNibNamed().
I found here the answer, that i should not set a custom class for the top level view, which will result again in "not coding compliant". So either way it still doesn't work...
Its difficult to tell without seeing what your connections are in the Xcode inspector, but sometimes if you connect an outlet and then rename it in your code, that outlet is still connected with the old name and you get a key-value compliance issue
Places to look are in the "User defined attributes table of your identity/inspector..
And also check your connections inspector

Xcode 4.4 Connecting a .h and .m to a View Controller

I'm using Xcode 4.4 and I'm trying to connect the .h and .m files to the view controller in my storyboard but the options I have for adding files are:
Objective-C class
Objective-C category
Objective-C class extension
Objective-C protocol
Objective-C test case class
Every tutorial and answer I have found is for the 4.2 version which goes the option of Objective-C subclass which I don't have. I was wondering if anyone knew how to do it in 4.4.
Thanks
I had the same problem and just found the answer.
First, make sure to read Xcode help about storyboard (in help menu, type story...)
Second, Make sure XCode show you his full interface (in the tool bar, select all three view icons, or at least the bottom right and bottom left icon.
There is a video in the help which explain how to do so.
why you have to connect .m and .h to the view controller ?
try the easy way: file - new file - objective c class and in the second windows check "with XIB interface".
with this, you'll get .m .h and .xib !

How to generate .m/.h files from Storyboard?

Is there a convenient way to generate code from any new view controllers I've created on the storyboard? For example when you create a new iOS application, XCode will set up a skeleton class for your view controller.
Thanks!
I don't think so. You need to create a new ViewController subclass in XCode but uncheck the "Create Xib for this class" box (not sure if that is exactly what it says). Then select your newly made view controller in storyboard and change it to the class you just created.
Ok the skeleton you are talking about is just a template for your application. You are asking for a dynamic template generator from your storyboard and maybe Apple can figure out how to do this in a non distant future but in this moment I think you can't do that. After you created the storyboard file with your complex scheme you need to manually create all your viewController subclass you used in the storyboard. It's not a big deal ... I suppose your application doesn't have thousand ViewController so you can do it manually.
Apple are working hard to simplify developers job but Xcode can't do everything for you.
You can try to post this answer directly to Apple throughout the bugreport Apple website and post it as improvement to implement in future Xcode release.
Lets try it :)

UITableViewCells loaded from NIB always nil

I'm trying to create a simple form using a UITableViewController as documented in the Apple Developer Documentation here.
What I'm trying to do is located in the section entitled: "The Technique for Static Row Content"
I've created a couple of UITableViewCells and added them to my nib, but when I try and access them to add them to the UITableView (in the cellForRowAtIndexPath: method) they are always null.
It's like they are not being properly loaded from the nib. I've double/triple/quadruple checked my code to make sure I'm doing it exactly as detailed in the docs, but no luck.
Is there something obvious I'm missing here?
Have you made sure you've connected the IBOutlets in the nib file?
In your ViewController.h file you should have:
IBOutlet UITableViewCell *specialCell1;
IBOutlet UITableViewCell *specialCell2;
and then each of these should be "wired up" to the corresponding cell in the nib file. If not, they won't exist!
Figured it out...
When I added my parent view controller, I was using the simple "init". Switching to "initWithNibName" resolved the issue...
Still learning... :)

How can I make an view-based application that does not use a nib file?

I've choosen the "view-based" application template in Xcode. The myProjectViewController.m has the following code:
/*
// Implement loadView to create a view hierarchy programmatically, without using a nib.
- (void)loadView {
}
*/
That sounds good. But: The template generated a myProjectViewController.xib file. What I dont get is: How does Xcode connect the ViewController with that nib? Where's the part in the template code that says: "Hey, load that myProjectViewController.xib now!"? I mean... can I just delete that not-wanted nib file without setting anything else up appropriately?
You may wish to refer to my answer to this question, where I describe the specific files that need to be altered to do completely programmatic generation of your view hierarchy.
Also, some of the references linked to in the answers to this question may be of use to you.
yep you can just delete the nib and implement that method
IB connects using the name of the class in the NIb, in IB you actually set a view as the file owner of the view. so when you call initwithnib:"nibfilename" it knows what you are talking about.
The elements are wired up using IBOutlets and IBActions