How to remove 'cancel button' in a ResearchKit survey - swift

I've made a ResearchKit survey with 11 steps, but I'd like to remove the default cancel button that's on the bottom of every question.
I've come across this command:
stepViewController.cancelButtonItem = nil;
But I can't seem to find the right place for it.
Thanks.

The correct place would be in the delegate callback. The documentation states "The cancel button item is updated during view loading and when the value of the step property is changed, but is safe to set in the taskViewController:stepViewControllerWillAppear: delegate callback."
And as an example:
func taskViewController(_ taskViewController: ORKTaskViewController, stepViewControllerWillAppear stepViewController: ORKStepViewController) {
stepViewController.cancelButtonItem = nil
}
That being said, the functionality currently seems to be broken in the most recent version of ResearchKit per these issues on their repo.
https://github.com/ResearchKit/ResearchKit/issues/1273
It currently will disable the functionality of the cancel button, but does not correctly remove the button from the ORKNavigationContainer. If you find a solution, please let me know, had the issue posted on their repo as well as a few other places for some time now with no luck.

Related

swift - how to prevent two touches at the same time

For example, I have 2 buttons Change email and Change password, and each of them call functions with Alamofire request, and responce data should reload both the UI and data scheme.
The point is that this PUT requests change not only servers's data, but generate new token and get updated user's profile.
And when pressing buttons at the same time, at the same moment touches begin and end, app crash after parsing requests.
I'm blocking another UI elements(like textfields), I was trying to block another button, but when press it together, it's not works.
So how can I prevent the same time touch? I'm not good at OperationQueue, maybe thats'the way? Is there an option to check if operation not first at the queue and kill it?
Set isExclusiveTouch of your UIButton to true in order to trigger only one button action in a specific time.
This code will get all the buttons contained in the view and set the exclusiveTouch to true:
self.view.subviewsRecursive()
.filter { $0 is UIButton }
.forEach { $0.isExclusiveTouch = true }
This problem with the UIResponder object is very usual. However, your problem description is not clear and your implementation seems not so good.
Here, to resolve this quick touch event problem:
Your solution is debouncing the action event of UIButton.
Debouncing also helps to prevent multiple executions when a user mistakenly pressed a button (or any UIResponder object) multiple times so quickly that even the UI was not blocked till then. Following article may guide you more regarding the same:
Debouncing to tackle repeating user action

Property additionalActions of NSUserNotification seems not working?

To understand NSUserNotification better, I wrote a little test app playing with this class.
So far so good, except that no matter how hard I tried to feed the additionalActions property with array of NSUserNotificationAction objects, it never showed any difference but only one action button and a close one.
My expectation for this property is that the notification would show a pull-down menu containing the additional buttons I offer as it does in the Mac App Store update notifications.
Am I missing something? Or are you having the same problem, since it is a bug awaiting Apple to tackle?
Can you please try to click and hold down the action button in your notification? Does it show a drop-down menu of additionalActions?
Update
As it turns out, you can show the little chevron next to the action button by setting a true value for the private _alwaysShowAlternateActionMenu key on the notification. In Swift 3, it would look like this:
notification.setValue(true, forKey: "_alwaysShowAlternateActionMenu")
However, as I mentioned this is a private API and I strongly advise against using it if you want to distribute your App through the Mac App Store.
It is probably a bug. Setting up additionalActions will create the list, but not the little arrow icon. Holding down on actionButton will show the menu with the number of actions you set.
Besides setting additionalActions will cause several other problems. I will save this for another question.
Refer to another question.
show NSUserNotification additionalActions on click
P.S. I am using El Capitan APIs

How do I add a button to the InAppSettingsKit setting view (iPhone/iPad)?

I have been looking at the sample app provided by InAppSettingsKit and I noticed the use of a couple of buttons:
I would like to integrate a single red button in my app called reset, however I'm not sure how to do it. I've had a look at the code in the sample app and I'm a bit lost with it all. Please could someone help me out?
After spending a while searching through all the code and plists I managed to find the answer to my question. For those who are interested what you need to do is the following:
Add a row to your Root.plist file with the Type set to IASKButtonSpecifier.
Set the Identifier on this row as something useful e.g. 'myButton1'.
Add the following delegate method to the viewController you loaded the InAppSettingsKit from:
- (void)settingsViewController:(IASKAppSettingsViewController*)sender buttonTappedForKey:(NSString*)key
{
if ([key isEqualToString:#"myButton1"])
{
// Do some actions...
}
}
It's worth noting that the key is equal to the identifier you set in the Root.plist.
The only thing I haven't worked out yet is how to change the colour of the button; however I suspect this may be possible by overriding a method.
Great that you already found part of the solution. To customize the look, you should create a custom view using the IASKCustomViewSpecifier documented on http://www.inappsettingskit.com/. The yellow icon for instance is making use of this. In your case, you could return an instance of UIButton with a red background color (or a custom background image).
In this case, you don't need the buttonTappedForKey method to get the tap event but configure the target/action of your button as usual.

UISearchBar error when entering Searchbar textbox

I have found a strange error. I have been following this sample:
http://jduff.github.com/2010/03/09/throwing-a-uinavigationcontroller-uitabbarcontroller-and-uisearchbar-together/
I tested it and then tried to roll it in my app. It worked in the sample but not my app. In my app I would SIGABRT or BAD_ACCESS errors whenever I entered the textview inside the searchbar. The main difference was that I placed the Search on the second tab rather than the first. When I changed the taborder on my app to have the search on the first tab's navigation controller, it worked! It seems that unless I first enter the searchbar's textview. The object gets released and if I try to enter it later it fails. Very weird. I don't know enough about the objects here to say what the initialization sequence is but my guess is I need to do more initialization to get it to work.
go through the article in the link once more. especially through the "Setting up the Project" part.
In the article everything is set for the "selected view controller" which is the first one. And you say you implement everything to the second tab. Make sure you didn't implement everything in the first one of your project.
Let me know if this helps. If not I'll figure out something else.

hold down button to delete

Well, I cannot seem to find this anywhere on the site. So here is my question.
I have a test app which creates multiple buttons and gives each one a unique name via "+" in the toolbar. So far so good.
I am trying to find a way to press down on a button to get that Apple Jiggly effect and then delete that button and all subViews and data related to it.
Can anyone Please show me the way here?
Thanks,
Will...
Look at three20's TTLauncherView for an example of how this is done.
API: http://api.three20.info/interface_t_t_launcher_view.html
Code: http://github.com/facebook/three20 (specifically, the TTCatalog which has the TTLauncher in it)
You would have to implement deleting the subviews and data yourself after they hit the delete X box.