Assign Radio Group to Radio Buttons - swift

I have several radio buttons
I need to assign a radio group to it so that only one radio button is selectable at a time.There is no radio group option.I have tried
Assigning a single action outlet to all buttons
Putting all buttons in a custom view
None of this works.

In the old days, NSMatrix was the class that provided the radio group behavior. If you look up the docs for that class, you'll find the following note:
Use of NSMatrix is discouraged in apps that run in macOS 10.8 and later. If you need to create a radio button group in an app that runs in macOS 10.8 and later, create instances of NSButton that each specify a button type of NSRadioButton and specify the same action and the same superview for each button in the group.
So there are three things that all need to be true at the same time for this to work:
Your buttons all have to share the same superview.
Your buttons all have to have the same action.
Your buttons need to have their button type set to NSRadioButton.
I tried this out just now. I created a button in a view in my storyboard, set it's button type to "Radio" in the Attributes inspector, and assigned an action. Then I duplicated that button several times, and ran the app. The radio behavior worked automatically.
If it's not working for you, I'd start by doing what I did above. Just create a single radio button and set it up with an action. Then duplicate it a few times and test. If that works (it should), then either see if you can use that technique to get what you want, or look at what's different between what you want and what works.

Related

Difference between Buttons and onTapGesture

I’m quite new to swiftui and I was curious on what’s the difference between using a button displaying an image or an image with onTapGesture modifier that make an action just like the action on buttons.
In the use case you've described you can use either but for reference, Apple provides the following guidance in their documentation for onTapGesture:
If you are creating a control that’s functionally equivalent to a Button, use ButtonStyle to create a customized button instead.
onTapGesture adds an action to perform when the view recognizes a tap gesture and can be tailored to respond to any number of taps (with 1 being the default).
Buttons are a control that performs an action when triggered and have the benefit of automatically adapting their visual style to match the expected style within different containers and contexts.
In iOS and watchOS, the user triggers a standard button by tapping on it.
In macOS, the user triggers a standard button by clicking on it.
In tvOS, the user triggers a standard button by pressing “select” on an external remote, like the Siri Remote, while focusing on the button.
For more information please refer to Apples documentation here: https://developer.apple.com/documentation/swiftui/text/ontapgesture(count:perform:)
https://developer.apple.com/documentation/swiftui/button
I would recommend using Button when you want the feature of a button. I noticed that images cannot be used as buttons with Voice Over on. When I changed those to use Button instead, it fixes the problem.

What happens if you click disabled UIButton

The title doesn't have enough details so let me explain what I mean. So if I disable a UIbutton in my viewDidLoad func (and just to check i'm doing it right I have my code below for disabling) but then I do a drag and drop IBAction function in the same class, if it's unlickable but then I have that, what happens. Does it still stay unclickable?
I would test myself but currently can't test as i'm on school computers and i'm waiting for a sys admin to allow access to the debug processes.
button.isEnabled = false
By disabling the button, you are essentially making inactive. This means a few different things for different elements of the button. You can read more about it in the Documentation.
In regards to ctrl+dragging into the code, it will not react to any actions. The whole point of it is that it basically becomes 'unclickable'. So for example, if you have default layout, it will grey it out and not react (style-wise) when it is clicked. This is the same with any IBAction on the button. It's commonly used to disabled a button until something is satisfied, for example, in a form that all slots are filled etc.
Here's a picture of the default one disabled.

draw button as combobox with ios

I'm attempting to override the onDraw method of a button because I want to create a different styled button. I want to create a button like combobox with iOS SDK. I've already found source code, but it will not work.
Try this for combo box in ios.
IosCombo
Depending on how many entries you're trying to choose from, you might want to look at UISegmentedControl. It's like a radial button, where you can select one "active" option (leaving one or more "inactive" options). It gets cluttered and it becomes hard for the user to select the option they want if you have a lot of different options though.

radio button parent in code

In B4A, it is possible to add radio buttons to a parent (or group them) - such as a panel, instead of using designer? I have used addview to add 3 radio buttons to a panel but no luck.
I was using designer and then decided to try 100% code but I am having no luck getting them to select properly
There should be no problem adding radio buttons with code. Can you post the code that you tried?

Choose correct UIButton on dynamiclly created buttons without tags

I am loading up a plist file and creating buttons based on this file. These buttons can change at any point during the application running (which will trigger an update of all the buttons etc).
One set of buttons represents a list of categories. So I may have a house button, car button, etc. No matter what button is pressed it will call my categoryButtonPressed:(id) sender function. I need to know what button called it and load a second set of data based on the button (category) that was pressed.
So if I press the house button, the function needs to load the house data, but how can I determine what button was pressed in that function. If I use tags I have to know that the house button is tag 1, car is tag 2 and so forth. BUT I don't know if there will even be a house button until I read that file. Do I need to code the tag into the plist file as well?
OR is there a way to loop through my Array of UIButtons and determine this? Any advice?
And last, if I create my own extended version of UIButton that added a "name" variable, would I would still be out of luck because the action would pass the UIButton base and comparing my extended class to the base would always fail correct?
Thanks for any and all help!
And last, if I create my own extended
version of UIButton that added a
"name" variable, would I would still
be out of luck because the action
would pass the UIButton base and
comparing my extended class to the
base would always fail correct?
The action is passed by whatever control, of whatever class, the action was registered with. Creating your own custom button with additional properties seems like the way to go.
You could also set the tag of the button as the index in your button array, or the index in the plist that the button corresponds to.