How to fix button clicked not updating but others do [closed] - swift

Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 3 years ago.
Improve this question
I'm making a math game. Every time I click a button a new question should appear with different results to choose from.
However every time I click the button which I think is the result it doesn't update the text but the others do.
See github: https://github.com/Combii/BrainTrainerSwift

Use UIButton.setTitle(, for:) method. I suggest you to change code in ViewController.swift:
func setNumbers(numberDic: Dictionary<String, Int>) {
let btns = [bt1, bt2, bt3, bt4]
UIView.performWithoutAnimation {
for (position, number) in numberDic {
btns[(Int(position) ?? 0) - 1]?.setTitle(String(number), for: .normal)
}
}
}

Related

Checking the entered data for correctness swift [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed last year.
Improve this question
How can I make a check for the correctness of the entered data?
For example, the user needs to enter a digit, and until this is done, the program will not skip it further
In my case, you need to make sure that the user entered an integer, and not a string, double, etc.
Just create an infinite loop. If your read is successful break it. Something like:
while true {
if let line = readLine(), let value = Int(line) {
print("value", value)
break
}
}

Flutter how to add a 0 behind a hour if the hour is less than 10? [closed]

Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 3 years ago.
Improve this question
Im trying to check if an hour is below 10 so i can add a 0 behind it to make it the right hour format.
All my efforts till now haven't worked out.
Thank you for you time
You can use padLeft() method on strings. It takes width and padding parameters. You can use it like this:
print("5".padLeft(2,"0")); // Prints 05
print("14".padLeft(2,"0")); // Prints 14
you can try this;
var now = new DateTime.now();
String newHour = now.hour.toString();
if (newHour.length > 2) {
newHour = "0"+ newHour;
}

How do I update this variable with data [closed]

Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 3 years ago.
Improve this question
New programmer here! I'm working with a network request and below is a snippet of my code. After I complete the network request I want to store a value from the request into a variable. However, when the variable is called outside of the if let statement it is NOT updated. Essentially, the print statement inside the if let statement prints the value I'm looking for, but the print statement outside of the if let statement prints the default value I set for that variable. The variable is global. I need to use that updated variable elsewhere in my code, any ideas?
if let data = data {
self.nameLabel.text = data.name
person = data.name
print(person)
}
print(person)
First of all you didn't showed complete code so I am guessing you need main queue to update your UILabel first as shown in below code:
DispatchQueue.main.async {
self.nameLabel.text = data.name
}
next thing is if you want to access the value somewhere else once your request completes and UILabel updated then you can get the value from it this way:
let value = self.nameLabel.text!
And if you want to access the value once request complete then you can use closure and HERE you can check example of it.

In Unity know which button is clicked [closed]

Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 7 years ago.
Improve this question
I have two buttons create and join. Both button's on click event I move to next scene, but in next scene I have two scripts networkmanager and networkclient.
Now if I press create button I want to call only networkmanger not networkclient. So how can I disable the networkclient script and join I want to disabled networkmanger?
How can I know which button is been pressed?
public void OnPress(){
string name = this.gameObject.name;
switch(name){
case "Create":break;
case "Join":break;
}
}
You can read the name of the object the script is attached to.
If this is not suitable for any given reason (both scripts are on same object), you can pass a parameter to the method.
public void OnPress(string name){
switch(name){
case "Create":break;
case "Join":break;
}
}
then you give the name in the inspector.
The final way is to use two different methods for each button.

Unable to set member variable [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 8 years ago.
Improve this question
Very strange issue.
I have the following code:
NSDictionary* notificationUserInfo = [pNotification userInfo];
NSManagedObject* newShoppingFilter = [notificationUserInfo valueForKey:#"shoppingListFilter"];
self.shoppingListFilter = newShoppingFilter;
NSLog(#"%# tapped", [newShoppingFilter valueForKey:#"name"]);
For some reason the self.shoppingListFilter = newShoppingFilter is not setting the variable.
I assume that this is some issue with not initializing the self.shoppingListFilter variable in some way but I cannot figure this out. The NSLog shows the right output, newShoppingFilter is not null but self.shoppingListFilter is.
Any help is appreciated.
I bet newShoppingFilter is nil. Most likely, there is no key "shoppingListFilter" in the notification user info dictionary.
Set a breakpoint at the line that assigns a value to self.shoppingListFilter and check the value of newShoppingFilter. Also display the entire contents of notificationUserInfo.
Post the code that creates the user info dictionary and passes it into the notification that you are posting. That would help track down the problem.