How can I disable the user interaction for the Cancel button of my watchOS interface controller? - apple-watch

In my Apple Watch app, one of my interface controllers has a Cancel button at the top left corner. In my case, once a particular action is completed, I don't want the user to go back to the previous screen, so I want to disable the user interaction for that Cancel button. Even if I change the title to an empty string, user interaction still stays enabled.

We can't disable the back/cancel button user intaraction but can load controller without cancel button.
presentControllerWithName("NewInterfaceController", context: nil)
presentControllerWithName this will present controller with cancel button. If we use like below won't get the cancel button.
WKInterfaceController.reloadRootControllersWithNames(["NewInterfaceController"], contexts: ["NewInterfaceController"])
reloadRootControllersWithNames this will make our controller as a root controller so we won't get cancel button. This is how i resolved my issue. Hope it will help you as well.
NOTE: here [ ] is the syntax. exp: ["NewInterfaceController"]

You can't disable user interaction for back button.
But you can change a bit the way you present your views to accomplish what you want.
Start with your normal view. Check if you need to show the user the login. If you do, then present the login view Modally. At the end of login you close the modal view and you're back to normal view, without unnecessary back button.

This is simbesi.com's answer in watchOS 7/Swift 5.
Presenting the new controller modally:
presentController(withName: "NewInterfaceController", context: nil)
Presenting the new controller by replacing the root controller:
WKInterfaceController.reloadRootControllers(
withNamesAndContexts: [
(
name: "NewInterfaceController",
context: "NewInterfaceController" as AnyObject
)
]
)

Related

Storyboard iOS5 - How to prevent the storyboard changing when pressing the Segue button

I've created an app using the new iOS 5 Utility app template. Since the previous SDK, we now have to use storyboards for the GUI (which I do like using) but I am wondering how to prevent the "Segue" from flipping the view to the next view on the storyboard.
By default there is a button which when pressed flips to the "FlipsideViewController" and I would like to use this button as part of a login form but I need to stop the storyboard going to the Segue unless the credentials are correct. I have all my login code written but cannot prevent the page from flipping. The method I thought would do this actually prevents the user from going back by clicking the default "Done" button on the "FlipsideViewController".
Can anyone help?
You have to connect the button to an IBAction instead of a segue. In the action, check if the credentials are correct, then call performSegue: to perform it.
You will have to connect the segue directly from the view controller to the next scene instead of from the button.

IPhone sdk Login Control Segue issue

Hi I am new to Iphone Development and using iphone sdk5.
I am trying to implement an application through which I can login and show my application if login is successful, otherwise show the error alert.
problem which I am facing right now is that I have first view as View controller and I want to send the login details through clicking the login button and I want to perform the Segue through the same button if the Login is success full and show my TabBar Application. I have tried to implement basic push Segue as well as Custom segue... someway I was able to do through custom segue by checking the if(Flag)..then perform the segue... but the point is that I set the flag when i see the login is correct otherwise it should not set the Flag... now when I run the application I have to click the button twice and then the segue is performed and I get to my application TabBarController..
Please share some alternate ways also if you have better suggestions for me...
Any Ideas... please answer as soon as possible..
Thanks for time
The best method I can think of is:
You can ctrl-drag from the First view controller to the Second view (tab view controller). [You can use the view controller object at the bottom of the scene to do this.]
Create a identifier for the segue which was created, on the right hand side.
Define a IBAction for your Login button
Inside the IBAction do your FLAG checks
If the condition is TRUE then you call the
[self performSegueWithIdentifier: #"identifier_name_you_gave" sender:self];

Load the root view when app enter into background in iPhone sdk

I am developing an application which has 4 views and use navigation controller to navigate through. The first view is login interface. I just want to display login view when user press home button from second view. I have tried to use popToRootViewControllerAnimated in applicationDidEnterBackground. This does not work. Because I need to do this job only user press home button from second view (Second view contains MKMapView).
Can you please let me know what is the best option for this job? Basically I just need to check what view I am currently on.
Many Thanks
You could log a BOOL variable that the viewDidAppear function on your second controller sets to YES. And when you leave that view set it to NO. In applicationDidEnterForeground check it. If it is YES then the user left while in the second view.

Where should I "save" changes in my iPhone view to 'create new' of an object?

I have a view that creates a new core data managed object, and fills in all the required properties and also allows optional ones. I originally had a "Done" button on the top left, and when that was pressed, I validated the object then saved and removed the view.
Now I have an edit/done type setup on the top right, so sometimes there are two identical "Done" buttons on the top of the view. I want to switch the left side button so that it just has the normal "Back" button, then somehow validate and stop the view from being removed if it doesn't validate. I can't find any way to capture the method called by that back button and modify it, and viewWillDisappear doesn't work cause there's no way to abort the disappearing.
How can I make this work? I need to validate this, then save, then remove the view if validate and save worked only.
It sounds like your view is a perfect candidate to be pushed modally instead of through the navigation controller stack.
Push the view that creates your NSManagedObject modally:
[self presentModalViewController:yourViewController animated:YES]
Then continue to use your top right EDIT/DONE button for editing/validation as you currently are and when validation is successful simply save your object and dismiss the modal view controller from the parent view controller:
[[self parentViewController] dismissModalViewControllerAnimated:YES];
For more details check http://developer.apple.com/library/ios/featuredarticles/ViewControllerPGforiPhoneOS/ModalViewControllers/ModalViewControllers.html#//apple_ref/doc/uid/TP40007457-CH111-SW14
If you still want to use a button on the left hand side perhaps you can change the right button to say EDIT/CANCEL and add a DONE button on the left side that is only visible when you're not in EDIT mode. If appropriate you can point the DONE button to run through the same validation process before dismissing the modal view using the code above but it probably makes sense that the EDIT/CANCEL button takes care of it.
I hope this helps.
Rog
There is no documented way to intercept the standard back button of UINavigationController. If you want this functionality, your only option would be to customize leftBarButtonItem with a custom button.
When the user taps that button, you can first validate your object and then call popViewControllerAnimated:.
It's hard to mimic the look of the built-in back button, though.

How can I dismiss the view appeared by touching Add item in UINavigationController?

I have added add(+ symbol button) button to my navigation controller.
When I click it a view appears from bottom. I added a navigation bar and two buttons to it.
One save and one cancel button. And the view have one textEdit box. After editing I can save or cancel. If I touch cancel I need the view to disappear like it should go down again.
I think all iPhone , iPodTouch users use it. Like when they touch Add item then a view appears from bottom and when they cancel it goes down again. How can I make in this way in my application.
Maybe you're talking about a UIActionSheet?!?
http://developer.apple.com/IPhone/library/documentation/UIKit/Reference/UIActionSheet_Class/Reference/Reference.html