I'm a novice at Swift programming.
I've created an app with multiple identical buttons. I created one button with an action and then copied this button multiple times so that it uses the same action.
When one of the buttons are pressed, the image for the button changes ('image2' from 'image1'), and the button is disabled.
All good and fine so far.
I've then tried to create a reset button, where the buttons that have been pressed are enabled again, and the image for them changed back to 'image1'.
I did this by creating a collection outlet for a single button and then adding some of the other ones, one-by-one.
#IBOutlet var mybuttons: [UIButton]!
As I understand this creates an array with the buttons.
I then go over this array and update the image and enable the button, with a loop:
for myBubble in self.bubble
Now, my question is: Instead of having to drag each and every button to the outlet collection, would it be possible to add them to an array when they are pressed, and then run over that array instead?
I tried to create an array with
var mybuttons: [UIButton]!
and then use append(sender) when a button was pressed, but this gave a fatal error.
As mentioned I could solve this by simply adding all to an outlet collection but was wondering if there was a more elegant way to do it, since there are quite a lot of buttons.
As mentioned I'm a novice at this.
Thanks in advance.
Best regards,
Thomas
You have just declared your button array but not initialized it:
var myButtons = [UIButton]()
This way you declare and initialize an empty array and you can start to append your objects to it.
Related
Hi every one hope you're doing good,
I'd like to update my state with radio buttons that I generate dynamicaly.
my state is an array of objects, each object contains one question and 2 or more answer options,
each answer option is a radio button and by clicking it it will update one of the properties of the object.
I'm putting a link to get to the code, you'll be able to make changes and test them (but would not be saved)
I'll really appreciate you're help, thanks
https://scrimba.com/scrim/co9a8447a82665e7746ff8dcc
Hi how do create dynamic tabs? I wrote like this for 2 tabs. If it is more, it automatically adds those tabs. Can you please help with this?
From that, it should create 2 tabs. And it should set the correct URL when you click on the tab. If it gets more dictionary items in the array then it creates more tabs
What your searching for is React.createElement.
You can create a component from a string :
React.createElement('Upgrade')
for example.
However, dynamically creating a function in Webshop seems not feasible.
If you only need to do a history.push(PATH), I would recommend putting the function inside an onClick event. I'm not sure how do you want it to work.
As seen in the image, I have a list generated using an ArrayList. I want to make each item (for example the highlighted) a button to another page. Is there a way to do that?
There are a lot of ways to do that e.g. by looping the list and creating buttons which you can add to a container etc.
But you might be looking for button lists as covered here: https://www.codenameone.com/blog/button-lists.html
I have just started using visual studio c++ (2010) with windows forms, but have cannot for the life of me find out how to create new UI items in response to events. What I would want to happen is click a button, and have a new row, with a couple of text boxes and buttons appear, with onebutton to delete the row if I keep clicking, more rows will appear, named row0, row1 etcv. I looked at this page, (http://msdn.microsoft.com/en-us/library/aa984255(v=vs.71).aspx), about adding controls programmatically, but when I add a new text box inside a click event, the text box is only created inside the scope of the event (as expected!), but I want to be able to create it insde the newRow click event, but access it and . I thought of making a 'row' class, with row.text and row.deleteButton properties, and at each creation of a row, respective events will be created for button clicks and text edits.
Is there anyway to do this, ie a function that can be created that creates new objects by passing the required name?
The trick for this to work is that you need to have declarations outside of the event handler to keep track of the newly added UI components. In the link you've given the added TextBox is locally scoped within the event function, and this will be removed from the heap (i.e. memory) when the event is finished.
So one solution would be to add a list of UI components to your form, and then have the events add to or remove from this list of components. To get this solution working you possibly need to read up on lists of objects (or possibly dictionaries) and how to handle these.
Sorry for a rather general answer, but the question is also very broad... :)
I'm using the UI-bootstrap modal window in my Angular application and I'm running into some kind of a scope problem.
I've got a modal dialog which basically has two modes. At first, it displays a list of existing items for the user to select from. In case the item the user needs is not in the list, he can click "Create", then I hide the div containing the list and display another div which contains an input form so the user can add an entry to the list. This is all really trivial stuff. The buttons to toggle which div is being shown work fine. I basically have a boolean scope variable called "create", which takes care of this.
Then, in the modal-footer I have two save buttons. One is shown when in "list" mode and the other is shown when the user is in "create" mode. Again, works fine.
Now, when the user is in "create" mode and clicks the corresponding "save" button, then I need to process the form and finally switch the state back to the list, that is set the "create" scope variable back to false, but this is not working for me. It's like I'm dealing with more than one scope since the view does not update when I update the "create" variable from the button click in the controller.
I've created a working Plunker which demonstrates this, please have a look:
http://plnkr.co/edit/KDxzH21Lmthg0bc0cfUT?p=preview
I know this is probably something really simple I'm missing. Hoping someone can point me in the right direction!
EDIT: As per the suggestion below from Mik378, I created an "intermediate" object in the scope and assigned the "create" variable to it. Now this works like I wanted to.
I updated the Plunker: http://plnkr.co/edit/KDxzH21Lmthg0bc0cfUT?p=preview
If you're using scope.myVariableToReach, you have to change that by scope.oneIntermediateObjectNotAccessibleInTheChildScope.myVariableToReach.
Otherwise, when you set scope.myVariableToReach directly, it would change the child one, not affecting the outer.