-1

I have a text view on my app. I also have an About/Help button. When they click the About/Help button, it goes to another story board. When they click the "Back" button, it goes back to the original story board.

The problem I'm having is, how do I make it so when they go back to the original story board, that the text view won't revert back to what it originally had, but keep the input that the user had on it?

Okay, I have this code when the user presses a button called "Convert".

- (IBAction)convertButton:(id)sender {

    //Makes the text view into editable NSString
    NSString *input = _inputTextField.text;

    //Changes words that the user input.
    input = [input stringByReplacingOccurrencesOfString@"cool" withString:@"awesome"];
    //Some code here changes it to input2
    //Sends the edited input to the output text field
    _outputTextField.text = input2;
}

That means that if the user put "I'm cool." into the inputTextField, and then press the convert button, I want it to save his input, incase the user clicked the "About/Help" button that takes him to another window, because when he goes back, I want his old input to stay in the input box. But it doesn't do that.

Cœur
  • 37,241
  • 25
  • 195
  • 267
Hedylove
  • 1,724
  • 16
  • 26
  • You will need to store this value somehow. And then load that value back into the box on the viewWillAppear event, or similar – box86rowh Jun 15 '14 at 23:53
  • I know that... and that is what my question is.. how to do it. You didn't help me at all. – Hedylove Jun 15 '14 at 23:59
  • Sorry you feel that way, but if you want more in depth help you will need to show more effort (code you have tried, more pointed questions...) – box86rowh Jun 16 '14 at 00:13
  • To understand it better, I need to make a global string that will save the input2 into it when the user clicks the "Convert" button or outside touches. – Hedylove Jun 16 '14 at 02:20
  • 1
    The solution should really be put into an answer. – JasonMArcher Jun 18 '14 at 23:59

2 Answers2

0

you can set the text to the textview at viewWillAppear method in the ViewController. That method will be called when VC appears.

- (void)viewWillAppear:(BOOL)animated
{
    [super viewWillAppear:animated];
    myTextView.text = @"12345\nabcde\nABCDE";
}

Updated:

@interface ViewController () <UITextViewDelegate>
@property (nonatomic, retain) NSString *text;
@end

@implementation ViewController

- (void)viewDidLoad
{
    [super viewDidLoad];
    self.text = myTextView.text;
    myTextView.delegate = self;
}

- (void)viewWillAppear:(BOOL)animated
{
    [super viewWillAppear:animated];
    myTextView.text = self.text;
}

- (void)textViewDidChange:(UITextView *)textView
{
    self.text = textView.text;
}
Joey
  • 2,912
  • 2
  • 27
  • 32
  • Sorry, but this didn't make a difference. I need to make the "_inputTextField.text" equal to the "*input" that the user typed in. I tried setting it equal to "*input", but it says that "*input" is undeclared inside that instance. I have to make it save the input after pressing convert, and if touching anywhere outside the text fields. – Hedylove Jun 16 '14 at 02:00
  • @property (nonatomic, retain) NSString *text; declaring this in appDelegate.h file might help you.. – Nisha Jun 16 '14 at 04:42
  • This is confusing me. I don't know where to put what into which files. I keep getting a bunch of errors. – Hedylove Jun 16 '14 at 23:01
0

Solution by OP.

All we have to do is:

  1. Make sure the code for returned: is in the original .m file:

    //When the back button is pressed, this is what happens.
    -(IBAction)returned:(UIStoryboardSegue *)segue {
    }
    
  2. Make the "Back Button" connect to the "Exit" symbol on the bottom of the storyboard, and select "returned:" from the menu.

Cœur
  • 37,241
  • 25
  • 195
  • 267