I am developing mobile application using Xamarin.Forms. I have requirement of getting input in the dialog box. So, i have used UIAlertView for getting text input as like below.
I need to prevent an UIAlertView from closing on button click. I need to retain the UIAlertView dialog box even after the action initiated.
Can anyone please help me on this?
Regards,
Karthikeyan
You could create a custom UIView for this using a Xib file, however if you have no objection to the dialog closing and reopening should it encounter a validation issue then the following would work fine.
EDIT: Adjusted to allow you to pass back the validation message, as the primary message on the UIAlertView.
private string message = string.Empty();
public void recursiveDialog()
{
string input = string.Empty();
if(message == string.Empty()) { message = "Please enter the view name"}
var alert = UIAlertController.Create ("Save View", message, UIAlertControllerStyle.Alert);
alert.AddTextField ((field) => {
field.Placeholder = "view name";});
alert.AddAction (UIAlertAction.Create ("Cancel", UIAlertActionStyle.Cancel, null));
alert.AddAction (UIAlertAction.Create ("Save", UIAlertActionStyle.Default, action => {
input = alert.TextFields[0].Text
}));
if (alert.PopoverPresentationController != null)
alert.PopoverPresentationController.BarButtonItem = myItem;
PresentViewController (alert, animated: true,
action => {
// when a dialog is selected and returns, run validation
if(input == [whatever you want to use to validate it against])
{
// it failed because it already exists for example so change our message
message = "That view name already exists, try again.";
// already exists, so re-run method.
recursiveDialog();
}
else
{
// doesn't alread exist so carry on with whatever you want to do with the name provided.
// clear your message variable
message = string.Empty();
}
});
}
Related
I need the authentication via TouchID and FaceID and various "else" requests in my app. I managed to integrate it, so that after pressing the "button" to proceed, you move on to another VIEW.
The problem is that if the "cancel" item is pressed, however, the button that is connected to the next VIEW continues to work. I would like if the user presses "cancel" it will be shown on the home page. The Button is connected via Main.Storyboard to the second VIEW Controller created.
Below is the part of the code I wrote:
#IBAction func touchID(_ sender: Any){
let context:LAContext = LAContext()
if context.canEvaluatePolicy(.deviceOwnerAuthenticationWithBiometrics, error: nil)
{
context.evaluatePolicy(LAPolicy.deviceOwnerAuthenticationWithBiometrics, localizedReason: "Autorization Required", reply: { (wasSuccessful, error) in
if wasSuccessful {
print("Correct")
//let vc = self.storyboard?.instantiateViewController(withIdentifier: "SecondViewControllerID") as! SecondViewController
//self.present(vc, animated: true, completion: nil)
}
else
{
print("Incorrect")
}
})
}else{
print("TouchID/Facec ID not configured")
}
}
}
I am a beginner.
Try to do this:
Your "button" to proceed must call to your TouchID function. When you print "correct", you must create the navigation by code. If you print "Incorrect", dont create the navigation.
If you print "TouchID/Face ID not configured", you should show an alertview and maybe open the app settings configuration to enable/disable touch/faceId.
just wondering basically i have an Azure authentication system that opens when clicking on a facebook button or twitter button it then asks to authenticate the app and once logged in displays a UIalertview with the options to click "OK" or "Cancel".
I was wondering how once they clicked ok i could get it to display the next View?
I know my uialertview is called alert - so was thinking it would alert.Clicked (); then something in there but not sure what.
Here is the method that is processing the login and the alertview if someone can get back to me fast.
private void DoLogin(MobileServiceAuthenticationProvider provider)
{
var task = this.client.LoginAsync(this, provider).ContinueWith(t => {
MobileServiceUser user = t.Result;
this.BeginInvokeOnMainThread(() => {
UIAlertView alert = new UIAlertView("Logged In!", string.Format ("Hello user {0}", user.UserId),
null, "OK", new string[] {"Cancel"});
alert.Clicked();
alert.Show ();
});
});
}
Thanks
For example you could do this:
alert.Clicked += (sender, args) =>
{
// check if the user NOT pressed the cancel button
if (args.ButtonIndex != alert.CancelButtonIndex)
{
// present your next UIViewController, something like this
NavigationController.PushViewController(new YourNextViewController(), true);
}
};
For more information about UIAlertView check out it's documentation:
https://developer.apple.com/library/prerelease/ios/documentation/UIKit/Reference/UIAlertView_Class/index.html
When the user will click the "OK" button on the MessageBox below, something will happen for example, it will clear out the searchResult string and set it to "". Just to clarify, a message box will open up and show some string message (searchResult), but as soon as the user clicks on "OK" on that message box, searchResult will be set to "". How can I achieve this? How to create an event handler for this particular message box's OK button?
if (searchResult != "")
{
MessageBox.Show(searchResult);
}
There is no need for a listener. Just set searchResult to an empty string right after calling MessageBox.Show:
if (searchResult != "")
{
MessageBox.Show(searchResult);
searchResult = "";
}
You can use this if you are interested :)
http://msdn.microsoft.com/en-AU/library/system.componentmodel.backgroundworker.runworkercompleted.aspx
I need show a simple dialog with the question : 'Do you want to exit the application?' YES or NO.
This dialog will be shown when the user presses the back button of the device.
I know how I can show this dialog , but I don't know how to disable the back action: close app.
It's always closed.
If I understand you correctly, you want to display a confirmation dialog when the user clicks the back button on the main page of your app to ask whether they really want to exit. If the user selects Yes the app exits, otherwise you cancel the back navigation. To do this, in the MainPage class constructor hook up an event handler
MainPage()
{
BackKeyPress += OnBackKeyPressed;
}
void OnBackKeyPressed( object sender, CancelEventArgs e )
{
var result = MessageBox.Show( "Do you want to exit?", "Attention!",
MessageBoxButton.OKCancel );
if( result == MessageBoxResult.OK ) {
// Do not cancel navigation
return;
}
e.Cancel = true;
}
I have a NSSavePanel and I want to handle the "Cancel" button action to prevent closing the sheet. A want to show the confirmation alert above the savePanel sheet like it is done if you want to overwrite file when saving.
What is the best way to implement this?
Thanks
Some thing like this should work for you-
- (IBAction)showSavePanel:(id)sender
{
NSSavePanel *mySavePanel = [NSSavePanel savePanel];
if ([mySavePanel runModal] == NSOKButton) {
NSLog(#"OK selected");
}
else { // cancel button selected
NSBeginAlertSheet(#"Are you sure", #"Yes", nil, #"No", mySavePanel, self, #selector(sheetDidEndShouldDelete:returnCode:contextInfo:), NULL, sender , #"Your custom message");
}
}
For additional details you can go through this document - Introduction to Sheets