User Defined Runtime Attributes causing EXC_BAD_ACCESS from xib - iphone

I'm using a custom class for my UIViews, which I am controlling some configuration by using User Defined Runtime Attributes. This works fine when using storyboards, but when I use the same technique within a xib, my custom view class generates a bad access when trying to read the attribute.
As with User Defined Runtime Attributes in IB for iPhone not working I had to set the .xib IB version to 4.2 so it would compile. Is this just not supported?

According to the other post, it's not supported by iOS. Maybe it is with iOS 5's storyboards, but it doesn't seem to be for xibs.

Related

Add a custom UI Object (UISwitch) to an iOS project

I'm trying to add a custom UISwitch to my app using DCRoundSwitch, however I'm struggling to figure out how to implement it correctly. After adding the files to my project I went to change my UISwitch to a DCRoundSwitch but have run into several problems, including the unrecognized selector sent to instance error.
I've tried (1) going to the Xib, selecting the Switch, opening the identity selector and changing the custom class, but the only option I see is UISwitch. (2) I've also tried changing the UISwitch to DCRoundSwitch in the code, but that results in the error mentioned above when I run it.
I feel like I'm missing a step, but I'm not sure what. Do I need to delete the switch and re-add the new switch? I've never done this programmatically before.
Finally found a solution!
The way to add a custom UI object in IB (after adding the code to your project) is to drag a generic UIView object onto your Xib, resize it as needed, then switch to the identity inspector and change the class from UIView to DCRoundSwitch (or other custom object).
Caveat: If you don't see your custom object listed, try building your project or closing and re-opening xCode. xCode 4 and up should recognize it after you've added your code to compiled sources.
DCRoundSwitch is not UISwitch Custom Class. this is a inherited from UIControl. this mean is in interface builder you not set UISwitch CustomClass. UISwitch between DCRoundSwitch is not related at all. so you must set Programmatically.
Have you seen this? https://github.com/robertchin/rcswitch (I used that sample for my apps)

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 :)

Proper setup for universal OpenGL ES iPhone/iPad app in XCode 4

I've been trying all morning to setup a univeral OpenGL-ES app with limited success. I can easily get the default OpenGL template app to compile for both devices and run just fine by adding a new XIB file and setting the proper values in it. Where I'm having trouble is figuring out how to give each device it's own unique GUI. Currently both devices use the same ViewController.xib file that is created with the project. How can I create a separate XIB file that uses the same ViewController .h and .m files? Do I need to create a separate AppDelegate class for each device type, or can they be shared?
The standard approach is to have a base AppDelegate class, and then subclass this for each device. Each delegate would then load its own XIB file with the correctly sized UIWindow and add the views.

how to load a view using a nib file without using view controller

i am new to this objective-c
i want to load a view using nib file i created when i press a button .without using any view controller..
This is generally considered a bad idea if you don't know what you're doing, but if you really want to do this then there's 2 places to look, depending on what version of the OS you're developing for.
iOS 4
Look at UINib in the documentation. You can use this to load a nib fairly easily.
iOS 3.2 and earlier
Use NSBundle. There is a category, documented under the name "NSBundle UIKit Additions Reference", that adds a method -loadNibNamed:owner:options:. You can also use this on iOS 4.0 if you so desire.
In both cases, the owner object fills in the role of "File's Owner" in the nib, useful if you have actions or outlets specified on the owner. The method also returns an NSArray of all the top-level objects in the nib. Be careful, if you use this array you need to retain any of the objects that you want to keep, as the array (and all the objects) are returned autoreleased.
Try this. Should show you how to implement your UIView subclass.
http://markuzweb.blogspot.com/2011/05/subclassing-uiview-with-nib-file.html

How do I make a universal iPhone / iPad application that programmatically uses UISplitViewController and UINavigationController?

I couldn't find a good answer anywhere to this. I am using a UINavigationController for my iPhone app, with everything is generated programmatically, nothing in Interface Builder. I am trying to port my app to iPad, using a UISplitViewController and my existing UINavigationController, but I am not sure where I should have the logic of my program separating the view controllers for iPhone or iPad.
Do I set up my main file to use a different app delegate or do I use the same app delegate and have the user interface conditionally set up within it?
Besides this, whenever I try to compile my app on the simulator it does not recognize the UISplitViewController or even the condition in which I check if the class exists.
Can please someone put me in the right direction, remembering that I am not using any xibs?
If you want to see an example of a completely programmatic iPhone / iPad interface that uses a split view, you can download the source code of my application Molecules.
Within that application, I use one application delegate, but I set up the interface differently depending on which user interface idiom is present (iPad or iPhone). For the iPhone, I instantiate a root view controller which manages the appropriate interface for that device. For the iPad, I first create a UISplitViewController and attach it to the root window, then create my iPad-specific root view controller and place it as the detail view of the split view controller (with a navigation controller that I use for item selection as the left-hand controller for the split view).
Again, I recommend looking at that application project to see how I set this up programmatically. The code's available under a BSD license, so you can copy and paste this into your own application if you'd like.
As far as the compilation errors you're getting, you will need to migrate your application target to be a universal application using the "Upgrade Current Target for iPad" menu option. Once that has completed, set your build SDK to 3.2. Go to your application's build settings and set its Deployment Target to the earliest OS you want to support with your application (with 3.0 being the farthest back you can go).
Finally, you will need to weak-link UIKit. For how to do that, see my answer here. Weak linking of frameworks is no longer necessary if you are building using the iOS 4.2 or later SDK. Simply check for the presence of the appropriate classes at runtime by seeing if their +class method returns nil.