Before I start I want to explain that I'm looking for a general solution to my inquiry, I don't have any code to show because I haven't the faintest idea of how to start. Let's say I have a program in which I have 4 buttons, two on the right (red and blue), two on the left (white and yellow). If I were to press a certain combination of buttons I want to get a specific output an example would be if I touch the red button and then the white one the word "cow" appears or if were to touch the white one then the red one the word "chicken" appears. Is there any documentation that anyone knows of that can help me with my problem? Can this even be done with an array?
HotLicks has a valid answer, but I think an NSDictionary is a better solution. Create keys based on button presses, like:
#{ #"RedWhite" : #"Cow",
#"WhiteRed" : #"Chicken" };
Your code will be easier to read, and you can support three presses easily (assuming you're working with a timer that you invalidate after each press) by just adding another key; no recalculating your array:
#{ #"RedWhiteBlue" : #"America" };
Related
I tried and understood what could be the purpose of the accessibilityActivationPoint but in vain.
When a focused accessible element is activated, that property should indicate VoiceOver the specific area it's going to activate when a user double-taps the element (Apple reference) : for me, it's always the selected element itself.
I understood the selected element is considered as a block by VoiceOver, whatever the other elements inside. Once a double tap occurs to activate this block, VoiceOver calls accessibilityActivate to know what to perform (Apple reference).
1/. I've written many tests by creating a custom view including a switch control. Whatever the value of accessibilityActivationPoint inside (or outside on another switch control), the value of the switch control never changes. Is it a proper use case or am I totally wrong ?
2/. When we gather many elements inside one accessible element, how is VoiceOver able to activate one of them while they aren't accessible by definition ? Pointing one of them thanks to the accessibilityActivationPoint should work ?
Personally, I couldn't make it work and think that I'm really confusing accessibilityActivationPoint and accessibilityActivate.
Any help would be appreciated, thanks in advance.
Yes, you have the right idea with accessibilityActivate and accessibilityActivationPoint. Note that, in order for it to work, the accessibilityActivationPoint needs to be a point within the Control that you are trying to activate in on-screen coordinates (use the convert function!).
I think the short answer is "yes" to answer your second question, but, just to clear up confusion about when Accessibility Activation Point is useful, I'll go into more detail about it.
By default (aka, the default behavior for AcessibilityActivate()), when any view is activated by VoiceOver, VoiceOver will send a "tap gesture" to the center of the view. The position of this "tap gesture" can be changed by updating the accessibilityActivationPoint attribute on a view. Below, I have an example for how this property can be used.
Let's say you have a blank button (in the image below, the button is the gray box) next to some text:
For the purpose of accessibility, you may want to make the entire view that holds the button and text an Accessibility Element (so that VoiceOver users can easily understand that the button is associated with the text "Worldspace Attest"). In the image below, I am using Accessibility Inspector to show that the view holding both of these elements is an Accessibility Element.
Notice in these images that the button is not in the center of the view, but rather, it is to the right. When you activate this view using VoiceOver, the view will not select the button; instead, it will send a "tap" to the center of the view (which is the same as tapping the text, which does not do anything). In order to select the button, you have to set the view's accessibilityActivationPoint to be the on-screen coordinates of the button:
view.accessibilityActivationPoint = self.convert(button.center, to: UIApplication.shared.windows.first)
This should make it so that this button is usable by a VoiceOver user.
I hope this information clears up any confusion about the Accessibility Activation Point property. The example I used above can be found in this repository in the "Active Control Name" demo.
(using iOS8.3, Xcode6.3, OSX10.10.3)
Hi, I wonder if a WatchKit WKInterfaceGroup can be a Button ??
In my watchkit-application, I would like to maximize the touch-surface for a particular action.
I know that one can place one or more buttons in a goup (next to other things like labels, images etc). Having such a WKInterfaceGroup (called group) with small items in it - I thought of placing several buttons, all filling out the empty space between the groups container.
But by placing several buttons close to each other in the group, even if they all reference to the very same action, I realised that touching two buttons by the user's finger in the group would not lead me to the desired surface-increase.
The problem is, the user-finger touches more than one button at once and even tough, I gave all the buttons in the group, as just mentioned, the very same action behind, the action does not get fired off.
The solution might be, if possible, to define the entire group as a button. How would that work ?? (...maybe accessibility traits could help ?? or other....???). Or can you somehow overlay a button on to a group ???
Any idea appreciated !
You can use a WKInterfaceButton, change its content type to "group" in the attributes inspector in IB and fill it with whatever content you need.
I am learning Xcode(objective C). I want to make simple calculator.
I started by adding four simple buttons and one label. Two buttons are for numbers(1 and 2), and I added variables into .m file:
int *one = 1;
int *two = 2;
Next step what I've done is that I made action on button clicked and said that label take value from that button:
self.firstLabel.text=[NSString stringWithFormat:#"%d", one);
And I made same action for another button.
Everything is fine until this step, what I want to do next is when I click on number button to add value to that label, then when I click to divide(/) button to add / sign and when I click to another button to add another value.
I want to be something like this in label: 2 / 1, and when i click = button to divide them and show result. Thanks.
EDIT:
I also added label proper into .h, and when I click on button it shows me only one value in label.
Since you are just starting to learn obj C you may want to keep your calculator simple, building a fully functional calc. can get surprisingly complex. You should consider using an RPN approach, it will make things much easier, you can just push the numbers to a stack and perform operations one at a time.
Something like: 2, enter, 1, enter + enter.
You may also want to have a look at Stanford's iOS course on Apple University, the course is in Swift but the class project was a calculator so it should give you a good reference point. Hope that helps and good luck!
you should add a custom target for each button, i.e.,
- (IBAction)addDivide:(id)sender {
self.firstLabel.text = [[NSString alloc] initWithFormat:#"%# /", self.firstLabel.text];
}
Any action will update your label.
Just a further advice for you, don't name the label as "firstLabel", try to give it a name tied to its semantics.
You are only setting the int value to the label. You need to append the value maintaining the previous text so that it appears as "2 / 1".
I'll suggest using tags for the buttons and use a common method for number buttons in your calculator.
This is more sort of logical thing rather than specific to iOS and Xcode.
Similarly when "=" is pressed use a method to calculate the result.
i need one more help.
First question is: I understood that the sections, text, images, etc on a MonoTouch.Dialog will be created dynamically. But can i have buttons as well? If yes, how can i have the events of that button binded.
Second question is : Basically i have a search text, and a button, on the click of the button, the text is sent to the Twitter-url, to get the tweets, these tweets need to be displayed, now they contain, images, texts, and reply and a favourite. Can the search result and the Search Button+Edit box, be the part of one ViewController?
But can i have buttons as well?
Element in the DialogViewController often act like buttons. But if you want a real UIButton you can do something like: Monotouch.Dialog two tables
Can the search result and the Search Button+Edit box, be the part of one ViewController?
I don't see any problem doing that. Use the code from the above link and add a EntryElement.
the text is sent to the Twitter-url, to get the tweets, these tweets need to be displayed
Have you looked at TweetStation ? It's an open source application that is based on MonoTouch.Dialog. It can likely help you answer questions on both fronts.
I just can't get my head around this and possibly my title isn't perfectly clear. I am a newbie, learning how to program. I am creating a simple calculator and when the user selects any operand, the title of the operand changes its color from white to orange. I setup a switch statement and change setTitleColor. As soon as a digit is pressed the operand button returns to original state of color white. What I want to do is if the user then presses the clear button once, change the color of the last highlighted operand back to orange.
I am just stuck trying to figure out a way to return back one step. If anyone can give me an idea of how I can achieve this, I will really appreciate it.
There is nothing specific to iOS here. All you need to so is probably have a stack maintained or a simple lastUpdatedDigit variable tracking the last action performed. Here in your app its the last digit typed.
So when you want to change the color of the last highlighted operand back to orange all you need to do is access this lastUpdatedDigit variable & change its color. You are good to go.
Not sure if this answers your question. If i have misunderstood, then please correct...