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

  • SEARCH
  • Home
  • 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 7443217
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 29, 20262026-05-29T11:17:51+00:00 2026-05-29T11:17:51+00:00

i have been trying to copy text input from alertview textfield to a NSMutableArray

  • 0

i have been trying to copy text input from alertview textfield to a NSMutableArray that i will use later, alertview pops up and i enter the input to text field but when i press OK alert view disappears but doesnt copy text to my mutable array

here is my code

-(IBAction)add:(UIButton *)sender
{
    addCustomStand = [[NSMutableArray alloc] init];
    UIAlertView* dialog = [[UIAlertView alloc] initWithTitle:@"Enter a Stand Location"
                                                     message:@"  "   
                                                    delegate:self 
                                           cancelButtonTitle:@"Cancel"
                                           otherButtonTitles:@"OK", nil];

    UITextField *nameField = [[UITextField alloc] 
                              initWithFrame:CGRectMake(20.0, 45.0, 245.0, 25.0)];
    [nameField setBackgroundColor:[UIColor whiteColor]];
     nameField.text = @"";
    [dialog addSubview:nameField];

    if ([nameField text]){
        NSLog(@"Name Field %@ ",nameField.text);
        [addCustomStand addObject:nameField.text];
    }

    [nameField release];
    [dialog show];
    [dialog release];   
}

- (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex
{
    NSString *title = [alertView buttonTitleAtIndex:buttonIndex];

    if([title isEqualToString:@"OK"])
    {
        NSLog(@"Button 1 was selected.");
        NSLog(@"StandLocations %@ ",addCustomStand);
    }
}

here is my output on log screen

2012-02-07 20:26:57.315 Avicii[1399:b603] Name Field  
2012-02-07 20:26:59.720 Avicii[1399:b603] Button 1 was selected.
2012-02-07 20:26:59.721 Avicii[1399:b603] StandLocations (
    ""
)

anyone can help whats wrong with that code?

  • 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-05-29T11:17:52+00:00Added an answer on May 29, 2026 at 11:17 am

    That’s because [nameField text] doesn’t have user entered value yet when you added it in your [addCustomStand addObject:nameField.text];

    so change your adding into array in UIAlertView delegate method.

    -(IBAction)add:(UIButton *)sender
    {
        addCustomStand = [[NSMutableArray alloc] init];
        UIAlertView* dialog = [[UIAlertView alloc] initWithTitle:@"Enter a Stand Location"
                                                         message:@"  "   
                                                        delegate:self 
                                               cancelButtonTitle:@"Cancel"
                                               otherButtonTitles:@"OK", nil];
    
        UITextField *nameField = [[UITextField alloc] 
                                  initWithFrame:CGRectMake(20.0, 45.0, 245.0, 25.0)];
        [nameField setBackgroundColor:[UIColor whiteColor]];
        nameField.text = @"";
        // Note at this line
        nameField.tag = 100; 
        //
        [dialog addSubview:nameField];
    
        [nameField release];
        [dialog show];
        [dialog release];   
    }
    
    - (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex
    {
        NSString *title = [alertView buttonTitleAtIndex:buttonIndex];
    
        if([title isEqualToString:@"OK"])
        {
            // Note at this line
            UITextField* nameField = (UITextField *)[alertView viewWithTag:100];
            [addCustomStand addObject:nameField.text];
            //
            NSLog(@"Button 1 was selected.");
            NSLog(@"StandLocations %@ ",addCustomStand);
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I've been trying to build a LGPL copy of ffmpeg and I have tried
I've been trying to get an existing project working on local copy but have
I have been trying to follow this example (download the source code from a
I have been trying to use some objective C, i have got as far
I have been trying to lock a file so that other cloned services cannot
I'm trying to get a pyside button to copy text from a qlineEdit field
I have a working copy repository that I've been working in no problem; the
I have been trying to deploy a simple rails3 app from my mac(os lion)to
I have been trying to implement Win32's MessageBox using GTK. The app uses SDL/OpenGL,
I have been trying to find a really fast way to parse yyyy-mm-dd [hh:mm:ss]

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.