Xcode swift : connection from buttons to Text Fields - ios

I am new to swift programming and Xcode
However I am creating a dart counter app but having trouble connecting the buttons to Text fields
I have buttons numbered 0-20 on the main story board and three text fields (one for each dart) how do I connect the buttons to the UITextFields - I can’t figure this out
Thanks

Based on my understanding of your issue, you actually need to connect the buttons to the text field in code. There is not going to be a simple way to do this in the interface builder. What you are looking for is to have some action happen when the user presses a number, and this may be added to the current value in the text field.
Create a function that handles any number button being pressed.
#IBAction func buttonPress(sender: UIButton) {
print(sender.tag)
//TODO: process the button based on its tag
}
Update all of the buttons in interface builder to have a tag value according to their number. This will let you handle them all in the same function (above) and differentiate between them.
Update the TODO block to handle the action appropriately. I would start by adding a variable to keep track of which dart number you are on, and using a switch statement to handle putting the value in the appropriate dart text box.

So there is always a current text field. Maintain an instance property that points to it. When the user taps a number, use that instance property to enter that value in that text field. When the user taps Enter, change the instance property to point to the next text field.

Related

Slack Block Kit Plain-Text input element update text value

Im currently writing a small Slack App in Python using Bolt. Im creating a Modal in response to a slash command which consists of a few Plain-Text input fields and two date pickers.
On one of the text input fields i set dispatch_action to True and define on_character_entered as trigger action as suggested by the API reference.
This way i can handle the event issued when the user enters text into the field.
This does work great and i push a new modal view when a specific keyword is entered. I store the initial's modal view id and hash to access it again when the newly pushed modal view is submitted in order to call views_update() on it (api). The idea is to change parts of the text based on the input of the second modal view.
This seems to work, but does not quite do what i want. The Plain-Text input does not have a field for its value, only for initial_value (which is the only thing i change in the views_update()).
When i return to the first modal view which contains the text input it still displays the original text without reflecting the changes, but from the response of the views_update() call i can see that the initial_value was changed correctly.
I guess that the initial_value only sets the text when the view is created for the first time, but does this mean there is no way to update a text input's text value without recreating the whole view?
Okay i just found the solution here. Basically you need to force slack to rebuild the ui element (in this case the text input field) by giving it a new block id when calling views_update().
Then the initial value gets used to fill the text input thus solving my issue.

UIButtons pressed as Input for Text Field

Haven't found it on internet, searching on google I found Custom Keyboard as extension with is not what I need.
I need to make so that when you pressed my "Keyboard" on the bottom right (Its not actually a Keyboard, it is just a couple of UIButtons) the Inputs appear on the text field (Its the white space below ACTUAL CASH DEPOSIT).
So, when you press the text field, no keyboard should Appear, and When I start pressing the buttons of my "Custom Keyboard" the numbers should Appear.
I have found something similar in (Xcode 8 Swift 3). Using Custom Keyboard Extension with a particular Text Field But On my other Tap, Denominations I have multiple Input Fields. Like his image:
I know how to do all the code behind in terms of buttons pressed and calculations But I don't know how to make the input fields as a responder for my custom Keyboard.
You can't make it magically update - instead, I'd suggest binding all the buttons to a single function, and then then for instance use the tag property in IB to differentiate between them. Through that function update the text.
func didPressButton(button: UIButton) {
switch button.tag{
case 1: myTextField.text! += "1"
default: break
}
}
I'd caution you'll need to do some verification logic if you allow decimals so all numbers are valid.

How to make ios keyboard with two type of return button?

My app has a text field that accepts a number. After the user fills the number, I want my user to have two choice of return buttons. One return to run function A, and one return to run function B. They also have to hold down the return button for 2 seconds to make it work.
Does anyone know how to do this? Please answer in Swift.
Configure and add buttons to the text field's inputAccessoryView; this view, including its subviews (the buttons), will appear at the top of the keyboard.

Get keyboard show event in Unity3d

I am making a game in unity3d for iPad only.
In one screen I need to take text input from user and for that I use Input Field.
I need to make some UI change when user open keyboard by taping Input Field. For that I need keyboard open(show) event. Input Field give me just two event 1. Text Change 2. Lost Focus. But I need get Focus event.
I read official document but can't find any relevant event. I search on internet for event, I get keystroke event but I need keyboard open event before user start typing.
In native iOS app we use UITextFieldDelegate Method - (void)textFieldDidBeginEditing:(UITextField *)textFieldor UIKeyboardDidShowNotification. Is there any way in Unity3d to get this kind of behaviour.
For input field with the new UI there is an isFocused variable.
http://docs.unity3d.com/ScriptReference/UI.InputField.html
http://docs.unity3d.com/ScriptReference/UI.InputField-isFocused.html
#pragma strict
// Required when Using UI elements.
public class Example {
public var mainInputField;
function Update() {
//If the input field is focused, change its color to green.
if (mainInputField.GetComponent.<InputField>().isFocused == true) {
mainInputField.GetComponent.<Image>().color = Color.green;
}
}
}
So if your field gets focused and it returns true you can execute some code. That is, if I understand you correctly.
I can't find anything that lets you know the InputField has been selected but a workaround may be setting the Interactable property to false and having an 'Edit' button near the field. When the 'Edit' button is pressed, you can change the UI elements and set the InputField.interactable = true.

How would you go about disabling a button as long as 2 text fields are empty in Objective C?

I have a view controller that controls 2 text fields and an array that displays in a table. How would I go about keeping a button disabled until the 2 fields have at least one character and the array is not empty. I am thinking about using cocoa bindings, however I can't seem to figure out a solution.
Currently my button is binded to
BOOL buttonIsEnabled;
I use that in a notification function in order to keep the button disabled, except the button will only reenable if I call that notification function.
-(void)controlTextDidChange
This means if i make a change in an array, the button wont reenable until I re-enter text. I can't seem to figure out an alternative solution. Any suggestions? Thank you.
One solution:
bind the two text fields two two strings (say text1 and text2)
in the text field bindings check Continuously Updates Value
Add this code:
- (BOOL)buttonIsEnabled {
return (self.text1.length>0 && self.text2.length>0);
}
+ (NSSet *)keyPathsForValuesAffectingButtonIsEnabled {
return [NSSet setWithObjects:#"text1",#"text2",nil];
}
Lastly bind the buttons enabled binding to buttonIsEnabled.
Because of the Continuously Updates Value text1 or text2 will change whenever characters are added to or removed from the text fields.
And the + (NSSet *)keyPathsForValuesAffectingButtonIsEnabled method will cause a Key-Value change notification to be posted for buttonIsEnabled whenever text1 or text2 change.
You can create a custom cell, give outlets to your 2 textfields and button.
Now on cell for row at index path after filling the textfields text values, put a condition checking the length of the textfields. If length is greater than 0 you can enable the button or keep it disable.
Along with this you need to put same code in delegate method (textFieldDidChange) of textfield. So that when ever new text is entered the button gets enable or disabled.

Resources