How to change a button name through an array? - iphone

How do I fetch the value from API to an array and put that value into a button as its title from starting index.
For example, button 1 is named by array, index 0; button 2 is named by index 1 and so on.

[urButton setTitle:[urArray objectAtIndex:index] forState:UIControlStateNormal];

Related

'R Cannot be assigned to' error in Roblox Lua

I am trying to change the color value of a textlabel. I am doing so using:
script.Parent.Parent.toggled2.SurfaceGui.SIGN.TextColor3.R = 0
script.Parent.Parent.toggled2.SurfaceGui.SIGN.TextColor3.G = 255
script.Parent.Parent.toggled2.SurfaceGui.SIGN.TextColor3.B = 0
basically it navigates to a button (a part, parent of the script) then to the group its in, then to a part with the text (in this case toggled2) then to the surfacegui inside then the textlabel (which is named SIGN) it then modifies the TextColor3 attribute 3 times at once, adjusting all the R,G,B values.
Why wont it let me alter the value? do i have to do something like :new() or .new()?
In order to assign a value to the TextColor3 property, you have to pass a Color3 object :
local sign = script.Parent.Parent.toggled2.SurfaceGui.SIGN
sign.TextColor3 = Color3.new(0, 255, 0)

Set tag to button via prepareForSegue

I have a tableViewthat passes data with prepareForSegueto a new ViewController when pressed. In that ViewController I have a button that I want to use the tag function on.
Is it possible to set tagvia prepareForSegue?
If row 1 in table view is pressed, destination.button.tag == 1and if row 2 is pressed destination.button.tag == 2 and so on

How to make jbutton sum up the values of my jradiobuttons

I'm making a project in jFrame. It has 15 jRadiobuttons. What I want is a jButton to add the selected jRadioButtons and display the sum in a jTextField. Can anyone help me? I've been doing this for 3 days and cant get it right.
So you have numbers as values of the radiobuttons?
Then try it like this:
When the button is clicked, go through a foreach loop of all radiobuttons.
in the loop, check if they are selected. If they are, you add their value to the Sum.
Is that what you were asking for?
EDIT
You create A List containing all radiobuttons.
In the Listener of the Button you write:
int sum = 0;
//foreach loop
for (jRadiobutton rbutton : rbuttons){
//Check if the button is selected
if (rbutton.isSelected){
sum += rbutton.Value;
}
}
I hope this is good enough explained.
Maybe the Syntax isn't correct, i haven't used java for a while now...

Differentiating between dynamically generated buttons

I have ten options on a view controller, each of which 'pushes' to the same new view controller displaying a specific amount of buttons (for each option a different amount of buttons may be available, ranging from 3 buttons through to 15). Currently, my code is performing similarily to the answer posted on this question.
All these buttons are created dynamically (the amount obviously depending on the length of the array) for each option using a for-loop:
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
{
if(option 1) {
Array contains different values...
}
if(option 2) {
Array contains different values...
}
etc...
for(int i = 0; i < xCoordinatePosition.count; i++) {
UIButton *imageOne = [UIButton buttonWithType:UIButtonTypeCustom];
[imageOne setTag:i];
[imageOne addTarget:self action:#selector(webViewChanged:) forControlEvents:UIControlEventTouchUpInside];
}
}
As you can see I've set a tag for each button to differentiate between the dynamically created buttons, as I want each one to display a different UIWebView when selected.
When I've selected an option and NSLog the resulting tags of each button on a results page, I get the reply I'm after: 1, 2, 3 etc.
- (IBAction)webViewChanged:(UIButton*)sender
{
NSLog(#"%d", sender.tag);
}
The problem is, I want a unique number for each button in regard to ALL option buttons - currently each of my ten options returns with buttons that have the tags 1, 2, 3 etc. up to ten, whereas I need the first option return with 1-10, the second option return with 11-20 etc, as each individual button will be returning something unique.
For example:
Clicking the button with the tag of 7 on one option will bring up a completely different web-view to clicking on a button with the tag of 7 on another, therefore I need to make a distinction between every button.
Does anyone know how I could set the tag so that is unique for each option (instead of just setting each button of the currently chosen option to be unique like it does currently)?
Just use another integerVariable which have the values multiple of 10.
int factor;
if(option 1)
{
factor = 0;
}
if(option 2)
{
factor = 10;
}
etc..
Then put tag as,
[imageOne setTag:i+factor];
If I understood your question correctly, one way to solve the problem can be to set a base tag for each option like 100, 200, ...
So, in your prepareForSegue:
int baseTag;
if(option 1) {
// Array contains different values...
baseTag = 100;
}
if(option 2) {
// Array contains different values...
baseTag = 200;
}
// etc...
And in the for loop, simply:
[imageOne setTag: baseTag + i];
For option 1, your image tags will start from 101, and for option 2, from 201, etc.

jquery selector - how to sort the iterated objects

Let say there are 3 divs Div1, Div2, Div3 and all have the class "ui-selected"
To iterate the div selection you can use something like below
$(".ui-selected").each(...)
The above iteration, references each div in the same sequence as they are added to the Document.
How do we sort the selection.
For e.g if Div1 represents a value of 30, Div2 represents value of 10 and Div3 a value of 40
the iteration when sorted should be as
Div2 , Div1 and Div3.
Right now the list iterates in the order of how they belong in the Doc model.
Is there a way to sort the jquery selection?
Assuming you have a way to know the "value" of each div, you can use the sort method.
$(".ui-selected").sort(function(a,b){
//sorting logic here
}).each(...);