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 6347179
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T21:09:49+00:00 2026-05-24T21:09:49+00:00

I have a modalviewcontroller and have two buttons on it: Cancel and Save. There

  • 0

I have a modalviewcontroller and have two buttons on it: Cancel and Save. There is a UITextField which is editable.
Whenever I click on save button I do save it but the text doesnot get save because when I click on the button to open the modalviewcontroller, the text disappears. Dont know whats wrong with my code.
Here is my code :

- (void)viewWillAppear:(BOOL)animated {

self.cancel = self.navigationItem.leftBarButtonItem;
self.save = self.navigationItem.rightBarButtonItem;

UIBarButtonItem *cancelButton = [[UIBarButtonItem alloc] initWithTitle:@"Cancel" style:UIBarButtonItemStylePlain target:self action:@selector(cancelAction)];
self.navigationItem.leftBarButtonItem = cancelButton;
[cancelButton release];

UIBarButtonItem *saveButton = [[UIBarButtonItem alloc] initWithTitle:@"Save" style:UIBarButtonItemStylePlain target:self action:@selector(saveAction)];
self.navigationItem.rightBarButtonItem = saveButton;
[saveButton release];

[super viewWillAppear:animated];
}

-(IBAction) cancelAction{
[[self parentViewController] dismissModalViewControllerAnimated:YES];   
  }

  -(IBAction) saveAction{
 NSString *text = [textFieldBeingEdited text];

[textFieldBeingEdited setText:text];
[self setDescription:text];


[[self parentViewController] dismissModalViewControllerAnimated:YES];   
   }

I am not sure if I have to use the following code to save the text in textfield :

- (void)textFieldDidEndEditing:(UITextField *)textField
   {
[self dismissModalViewControllerAnimated:YES];
   }
  • 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-24T21:09:49+00:00Added an answer on May 24, 2026 at 9:09 pm

    I don’t see in your code anywhere that you are setting the text in the UITextField when the view appears. You can add some code to your viewWillAppear method to set the text when the view appears, such as:

    [textField setText:[self description]];
    

    (It looks like you are storing the NSString in the description variable.)

    Also, if this is some kind of string that could be considered a User Default, you can store the string there. I’ve used this before and it populates my UITextField nicely.

    Code Example:

    -(void)viewDidLoad
    {
    stringValue = [[NSUserDefaults standardUserDefaults] stringForKey:@"string"];
    [textField setText:stringValue];
    }
    
    -(IBAction)saveAction
    {
    stringValue = [textField text];
    [[NSUserDefaults standardUserDefaults] setObject:stringValue forKey:@"string"];
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a view controller which presents a modal view when a certain button
I have a UIViewController called LoginViewController. The UIViewController has two UITextField, username and password.
I have some view controller, and when I click some button I make modalView
I have a NavigationController that present a view (ShoppingController) with a button which one
I have a UIViewController which I present a modalViewController in. After the modal view
i've created a login screen via a modalviewcontroller. But certainly i have a problem
Have you ever seen any of there error messages? -- SQL Server 2000 Could
Have just started using Visual Studio Professional's built-in unit testing features, which as I
Hi I have a modalViewController that I am popping up using [self presentModalViewController:myController animated:YES];
I have a viewController that presents a modalViewController when a UINavigationBarItem is touched. After

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.