Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8626479
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T08:02:31+00:00 2026-06-12T08:02:31+00:00

In my application when a user clicks on the save button in the toolbar,

  • 0

In my application when a user clicks on the save button in the toolbar, the user is then prompted through UIAlertView for which way they would like to save their current work by choosing either to save as an image or save as a play. When the user selects save as a play they are then prompted with a 2nd UIAlertView which also has a text field for them to insert the name for the play. What I am trying to achieve is so that when no text is inputted, the Ok button is disabled and when the length of the text typed in is 1 or more, the file is then able to be saved (using archiver, this works correctly so this is not an isue) and the Ok button is then enabled. Listed below is the code that shows the two alert views, as well as what happens when different items from the views are selected.

- (IBAction)selectSaveType {
UIAlertView *message = [[UIAlertView alloc] initWithTitle:@""
                                                  message:@"Please Select an Option."
                                                 delegate:self
                                        cancelButtonTitle:@"Save Play"
                                        otherButtonTitles:@"Save to Photos", nil];
[message show];

}
- (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex
{
NSString *title = [alertView buttonTitleAtIndex:buttonIndex];
if([title isEqualToString:@"Save Play"])
{
    NSLog(@"Save Play was selected.");
    [self GetFileName];
}
else if([title isEqualToString:@"Save to Photos"])
{
    NSLog(@"Save To Photos was selected.");
    //here is where we need to find how to call saveDrawing.
    [self saveDrawing];

}
else if([title isEqualToString:@"Ok"])
{
    NSLog(@"OK selected");
    UITextField *fName= [alertView textFieldAtIndex:0];
    NSString *NameFile = fName.text;
    [self savePlay:NameFile];


}

}

-(void)savePlay:(NSMutableString *)fileName{
//code here to save via archive.
   NSArray *pathforsave = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
   NSString *documentDirectory = [pathforsave objectAtIndex:0];
    //here we need to add the file extension onto the file name before we add the name to the path
   [fileName appendString:@".hmat"];
   NSString *strFile = [documentDirectory stringByAppendingPathComponent:fileName];
[NSKeyedArchiver archiveRootObject:matView.drawables toFile:strFile];

}

I have been trying to use the following code below to handle this, but when the first UIAlertView fires (which is the asking to select a play – no text field present) – the function below then is ran and crashes the application since there are no text fields in the first alert view.

- (BOOL)alertViewShouldEnableFirstOtherButton:(UIAlertView *)alertView
{
NSString *inputText = [[alertView textFieldAtIndex:0] text];
if( [inputText length] >= 1 )
{
    return YES;
}
else
{
    return NO;
}
}

alertViewShouldEnableFirstOtherButton is being hit when the first alert fires, then my application crashes in the simulator. Does anyone see why this would happen? Two things I am not so sure of

One – why the handle for the Ok button on the 2nd alert view to name the play is handled in the same block where the other buttons are handled. Since its a separate alert view, shouldn’t it be in its own block?

Two – why alertViewShouldEnableFirstOtherButton is hit when it hasn’t gotten to the 2nd alert view yet, it is called and runs with the first alert view, which crashes the app.

Thanks for your help, I am new to objective C.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-12T08:02:32+00:00Added an answer on June 12, 2026 at 8:02 am

    Delegate methods for an alert view will be called for any alert view you present. That being said this code will crash because textFieldAtIndex:0 does not exist on a plain alert view. To solve this all you need to do is add an if statement to the delegate method identifying which alert called the action.

    Edit: No longer identifies alert by name. Code now checks the style of the delegates sender.

      - (BOOL)alertViewShouldEnableFirstOtherButton:(UIAlertView *)alertView
    {
        if (alertView.alertViewStyle == UIAlertViewStylePlainTextInput) {
            if([[[alertView textFieldAtIndex:0] text] length] >= 1 )
            {
                return YES;
            }
            else
            {
                return NO;
            }
        }else{
            return YES;
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

In my application when a user clicks on a button I want to open
I have a setup application that if user clicks the same setup twice, they
Is there anyway to capture when the user clicks on the application icon in
How do I stop my application from going back when the user clicks on
Context: There's an application where you draw things on canvas. Where user clicks there's
I have 4 tabs in my iphone application. When user will click a button
I'm developing an application (user space) which send notifications of value changes via network.
I am working with a .Net 1.1 web application. There is a Save button
I am working on an application in which i need to save table data
I'm working on web application which, among other things, needs to save small file

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.