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

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)

Related

UIButton not getting the action within the swift code

Is there a reason why this action wont work within the code? Im dumb founded.
Try removing the outlet completely and reattaching the button to .swift file using the ^control key in Editor>Assistant mode.

Unknown class ZBarReaderView in Interface Builder file

I am working on the ZBarReader and getting an error
Unknown class ZBarReaderView in Interface Builder file
[UIView setReaderDelegate:]: unrecognized selector sent to instance
0x6859f20
Please look at an attached image at here or below so that you can picture what I am doing so far :-
In the storyboard, I do have a view and its custom class is ZBarReadView. I also wire it with IBOutlet in header file. In m file, I do
viewReader.readerDelegate = self;
and the error is shown after right after that.
Can anybody please point out what I have screwed up....
I found the solution in a thread over here
You need to add the following code in your applicationDidLaunch in your AppDelegate:
// force view class to load so it may be referenced directly from NIB
[ZBarReaderView class];
Should be running fine after that.
you can also try to download 64bits ZbarSDK.
I think the solution should be to add -ObjC flag to "Other Linker Flags" section in your Build Settings. If you can't do this, e.g. you are using Parse Framework that doesn't allow you to set this flag, you will probably have to use the provided solution of Morothat: Set in your AppDelegate the following:
[YOURCLASSNAME class];
It looks like you actually added a view in interface builder and tried to call it a ZbarReaderView for IB to hook up. Correct me if I'm wrong but in this instance I don't think Ib is going to know what you mean by ZBarReaderView.
I'm Also assuming you haven't actually implemented the delegate method in your .m file.

Weird XIB file issue

Experiencing a weird problem in a modified program written by me. In my first iteration, the view controller had an IBAction by the title userSpecifyingInput and had all my buttons wired up to this IBAction.
To make the design more sophisticated, I introduced userSpecifyingDigit and userSpecifyingLetter and accordingly had some buttons wiring up to the first IBAction (userSpecifyingDigit) and the next button wiring up to the second IBAction (userSpecifyingLetter).
Upon running my program, it gave me this error:
terminating app: NSInvalidArgumentException
Unrecognized selector sent to instance
And these selectors were alternating between userSpecifyingInput and userSpecifyingDigit which did not make sense as userSpecifyingInput was completely removed from my ViewControllers interface and implementations.
Now I am not sure why userSpecifyingInput still existed, but after dabbling with sent events, I noticed that the buttons were wired upto the new selectors as well as the old selector.
I had to manually remove the old selector from the touchupinside events for all the buttons.
Naturally this does not seem to be a very convenient way to go about proceedings and if the view controller selectors are modified then the touch events ought to be automatically removed.
Am I missing something here? This is a pretty open ended question with different answers
Eliminating an IBAction from your implementation will not remove any previous links to it in IB. I haven't heard of any XCode/IB preferences to shortcut this issue.
Sounds like the xib still thinks one of it's objects is hooked up to the UIViewController, but the function on the UIViewController is no longer there. To check and fix this...
Click on the xib file in the project navigator
Select the File's Owner
Click on the Connections Inspector
Verify that none of these connections are invalid
I would also look in the UIViewController to make sure no automagically created references exist here as well.

Changes in Interface Builder are not showing in SImulator or Device

I have a view that I created using default buttons and background in Interface Builder. The app runs properly. I added .png background images to the view and to the buttons. Build the app and run it and the updates do not show.
I've also tried something simple like changing the text of the button or add another button and the changes are not propagating.
I've cleaned targets, manually deleted builds in Finder, and have shutdown the computer. What else am I missing?
I had the same experience. It turned out that I'd renamed my class and my xib file, but in another class I was creating the view with:
MyNewViewController *myNewViewController = [[MyNewViewController alloc]
initWithNibName:#"MyOLDViewController" bundle:nil];
An oversight, but the surprising part to me is that when this Nib file didn't exist in my project, it managed to build successfully using a (presumably cached?) old Nib file... and the application happily ran, though showing an out of date interface.
Correcting what was passed to initWithNibName immediately corrected the issue for me.
This might sounds easy - but are you sure you linked up the view to the view controller in Interface Builder? I've done it before where I just forget to link them
I also had the same experience. For me the fix was to reset all content on the simulator.

Why is UISwitch only visible if I rename the class?

I had a class called OptionsTableViewController which inherited UITableViewController. I changed the superclass to UIViewController implementing the UITableViewDelegate and UITableViewDataSource protocols, because I needed the tableView to be in a specific position.
Now some table cells have a UISwitch as accessoryView. The switch is an instance variable, initialized With CGRectZero.
When changing the superclass to UIViewController the switches are not shown. But when I also rename the class (to OptionsViewController f. e.) it works.
Does anybody know where this strange behavior comes from?
I also tried to clean the project and I even deleted the build folder - but it seems, that the only solution is to rename the class.
I had a similar problem before, where the whole table view would not be shown unless the class was renamed.
Did you check to see if the names OptionsTableViewController and OptionsViewController are used anywhere else in your entire project, including in Interface builder nib files? Did you change all the names, as appropriate?
I found the reason for this problem. Although searching through the project XCode wouldn't find any files named OptionsTableViewController, but I found it included under Targets -> AppName. The file wouldn't disappear after Clean All Targets, so it is good to know that there still remain parts in there.