UIButton not getting the action within the swift code - swift

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.

Related

NSViewController StoryBoard Opening Window Error

I'm working on a program with several view-controllers, all of which I open at various instances as sheets, by controlling dragging from a button on one viewcontroller to another viewcontroller, and by selecting "Sheet". This has always worked, until now when recently tried to add another viewcontroller and connect it similarly. When I click the button to open it though, it crashes and throws the error: (NSButton): missing setter or instance variable. When I use the new button to open an old viewcontroller, it works, but when I use an old button to open a new viewcontroller, it doesn't. Anyone seen this before?
Turns out I wasn't specifying which viewController the data needed to be sent to so I made an if statement saying, "If this view controller, then" and "else" etc. which ended up working.

IBOutlets set up and working correctly are suddenly all shown as "!" in interface builder

While updating a UIViewController, all my IBOutlets are suddenly not registering with Interface builder. (note: i did not change any of these outlets in the .m file)
The class in the identity inspector is correct, the IBOutlets are shown as connected in the .m file and the app still runs fine.
However, I cannot add any new ones or edit the current ones. Whats happened here and how do i go about correcting it?
I've come across the solution. It was as simple as closing x-code and opening it again. Not sure why this happened in the first place, might be a bug, but if anyone gets the problem try that first.

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)

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.