iOS: Most suitable control for selecting from two options - ios

I am developing an iOS app in which I need a UIControl that allows the user to select between 2 options and 2 options only.
For example, assume I am displaying a form in my app in which the user fills up his personal information like Name, gender, hobbies etc. Here, gender is a possible field for which there are only 2 options (other options are possible, but let's say we don't want it in our app).
I thought it will be nice to use a customized version of the UISwitch for such a case.
But then, I am beginning to think that the UISwitch is applicable only in the context where something is enabled or disabled. Can it also be used in the context where user selects one of 2 choices? Does this go against Apple's design guidelines? If yes, then what other UIControl could I use for this? (I want to use something other than a plain dropdown)

UISegmentedControl is your choice.
You can feel free to use other controls (with customized look & feel) in your app, as long as it does not confuse users.

I'd suggest a UISegmentedControl, which has the behavior you require.

Related

Siri Custom Intent: Variable in "Shortcuts" app

I've created a custom Siri Intent. It is visible in the "Shortcuts" app. However, it allows me to pick only from donated shortcuts, without an option to specify own parameter.
Is it possible to create a Siri Intent that supports providing parameters using the "Shortcuts" app?
My Intents configuration
How the result looks like:
What I'd like to achieve
Notice, how the fields could be pre-filed (e.g. Item field). I'd like to have the same option for the phoneNumber.
EDIT
Parameters are now supported in iOS13. Documentation
Old Answer
As for now (iOS12), that doesn't work. The values for all custom parameters have to be known when you donate the Shortcut. From the documentation:
To donate the intent, create an instance of the intent class. Set its parameter values and add images to the parameters as needed.
To make it clear: A Siri Shortcut is really just a shortcut in the means of that it combines a series of fixed steps into a single button press. Think of it like a Amazon Dash Button. These buttons let you order a specific product with a button press. Say the button was created to order your favorite chocolate chip cookies from company A. So each time you press it, you order another pack of chocolate chip cookies from company A and only that. It doesn't take in any parameters during the press. So if your taste changes and you now want to order chocolate cranberry cookies from company A, you would need to replace your dash button.
As for the screenshot above. The shortcuts you see in the Shortcuts app with parameters are created by the Shortcuts team and use the URL scheme of certain apps. We can only hope that they open it up in iOS13.

Using md-select and md-autocomplete together

I'm trying to allow the users of my app to choose a single item in a big select (~2500 possibilities). So, as I already implemented md-chips with md-autocomplete in another app, I thought that all I had to do was to the same with a md-select. To my surprise, I didn't find a way to do that.
So basically I have 3 choices :
use md-chips but I can't limit them to one chip, I can show an error if two or more are chosen, but that's a rather weird UX to let the user choose two things and then alert them they can't.
use md-select, but from what I gathered, I can't use md-autocomplete, so choosing between 2500 objects is tedious
use md-autocomplete, but (not sure :) there's no ng-model, and worst my user can write about anything while I just want them to select one item
I'm sure I missed something in the docs, I just can't find a way to allow my users to select one and only one item with autocomplete.
Anyone ?

iOS Cross Cutting Concerns

I have a Swift application i'm working on that allows a user to save various settings about their profile. Throughout my code, there are times where knowing these settings/preferences are important for the application's business logic. One of them is where the user works (their job, (which is a row in a sqllite database that has an ID as a primary key). The user is allowed to select one (and only one) in the app at any given time. Think of it like a profile - they can work many jobs, but only have one selected.
The following are scenarios where knowing the workplaceid profile is important:
In my sqllite database, retrieving work/shift information based upon the currently selected work ID(so not the ID from the database, but the ID they currently have selected). I'm passing this into my query.
In an NSDate extension function, when I go to determine some things about their starting date, I need to retrieve their currently selected profile, and use that for the calculation.
Within a particular view model when I want to show/hide certain fields.
On an alert view to show something related to their current workplace.
Now I think the quick and dirty way to do this is simply create a wrapper class to your nsuserdefaults in a utility class. Sure, all your info is stored in sqllite, but your currently selected app preferences are in nsuserdefaults since I can change this around (and it will change). This would parallel my other cross-cutting concerns such as logging/error handling, where I could use similar utility classes for all my work.
The fact that I might call this helper/utility class from every single layer of my application seems like a typical red flag you wouldn't do. Whether it's logging, or a user service to get information.
I'm curious to know what other people are doing in scenarios like this. When you need nsuserdefaults from all over your app, is the answer "eh who cares, just make a utility class and call it wherever you need it" ? Or is there a best practice others have followed with well-designed iOS apps? I know AOP is something folks tend to recommend. Does that have a place in iOS?
Thanks so much stackoverflow :)
The user is allowed to select one (and only one) in the app at any given time.
This tells me you want to create a singleton class. Every time you want to change the profile, you hit the singleton class and set it. That class encapsulates all the logic to get/set whatever you need, and the accessor functions. That's what I've been doing in my ObjC code for many years, and it has served me well. It's extremely easy to debug, and the rest of the code needs to know nothing about profile management (unless it's the UI part where you choose a profile).

iOS - TextField recommend clear button behavior

In interface builder, there is a option that lets the user clear a TextField when they hit the (x) key. Since I think this option is extremely useful, I want to implement it in as many TextFields as possible.
However, the default implementation of the option is "never appears", and I want to keep as many default values as possible (because I think Apple considers the default interface behavior very well).
So my question is: when should I change the value? And if so, to what should I change it (always, when editing, or unless edition)? Here are some occasions I need to know:
On a table view
when the user enters his account details (email, password, name, etc.).
If you come up with other cases I should consider, please let me know!
Sorry, but I couldn't find any documents about this part of the UI in apple's documentation (which is very good and precise when it deals with standards).
This question is not about how to enable the key. Instead, it is when to enable it. I know it is my app and I can do whatever I want but I know how non-standardized apps feel like. So I want mine to be as standardized as possible so that the user doesn't experience any weird or usual behaviors.
This ABSOLUTELY depends on the you app design. Apple gives you these four options and it's up to you, which behavior fits your needs best, Apple does not care at all.
I personally only use it "while editing". In the past, I only used them for login or sign up forms.

Am I not understanding UIActivityViewController, or does the implementation currently suck?

I'm trying to move my app to use UIActivityViewController, rather than UIActionSheet, so that I get the fancy graphical sharing buttons rather than the textual buttons. (My app is targeted at iOS 6 only.)
After trying to work with it for a couple nights, it seems either I am totally misunderstanding how to use it, or the current implementation by Apple is terrible:
You can't specify a different message for different services. If I want something that will work across: Mail, Facebook, Messages AND Twitter, it's going to need to be 140 characters max, to work on Twitter. Is there a way to set custom content for each type of activity?
There appears to be no way to set a subject line or recipient for Mail messages. I've read the docs, they make it sound like this might be possible with an NSURL that uses the mailto: protocol, but in my tests, those URLs just get shoved into the message body. Is there actually a way to set the subject line and optionally, the recipients?
If I want to work around these shortcomings, and do my own custom activities by subclassing UIActivity, I have to use a custom image/icon. Therefore, I can't mimic the Mail activity with Apple's official icon, and e.g. implement my own custom activity backend that actually lets me set the subject line, recipients, custom body, etc. Am I wrong, is there a way to use Apple's service icons, but have a chance to customize the behavior? (The only callback I see is one that runs AFTER the activity has been completed, right?)
I hope I'm wrong!
Is there a way to set custom content for each type of activity?
Yes, I guess you should subclass UIActivityItemProvider and override method –activityViewController:itemForActivityType: with your logic (e.g. trim string to 140 chars for Twitter).
Then pass an instance of this class to -[UIActivityViewController initWithActivityItems:applicationActivities:].
Is there actually a way to set the subject line and optionally, the recipients?
You are right, the mailto scheme should be able to set these fields. If it is not working, I consider this as bug. (Didn't try this myself, but I will give it a check.)
Is there a way to use Apple's service icons, but have a chance to customize the behavior?
I think you can't do this. (Unless you want to hack those system activities.)
You are better off using a custom component that behaves like UIAcitvityController as it is quite limited, as you noted.
This is one example: https://github.com/hjnilsson/REActivityViewController , I just forked it from https://github.com/romaonthego/REActivityViewController to allow you to set the email subject field.

Resources