0

I have an iPhone app with three pages, each of which allows the user to enter some text. On the final page I want to concatenate all three strings and print it out.

Do I need to make a separate ViewController per page? I am trying to make it work with one ViewController in order to make the variable sharing easier but am not succeeding (crashes when I launch in main.m). If it is NOT possible to do it with one ViewController, how do I pass on the variables I recorded for the concatenation?

rmaddy
  • 314,917
  • 42
  • 532
  • 579
Hann
  • 30
  • 4
  • Here is a good answer: http://stackoverflow.com/questions/5210535/passing-data-between-view-controllers – Dániel Nagy Jul 31 '14 at 07:19
  • It is better to reuse controller if it is not complicated. There should be other reason that cause your app crash.What error u get? You can pass data as shown in above link. – Khant Thu Linn Jul 31 '14 at 07:21
  • Thank you so much for the link - that was precisely what I was searching for. I will try one of his methods, it's clean and makes sense to me. The error I was getting when I tried my way was a SIGABRT in return UIApplicationMain – Hann Jul 31 '14 at 07:27

1 Answers1

0

There are multiple ways of doing it. I achieved something similar setting variables in app delegate. I think it was a pretty strait forward way of doing it. In appDelegate.h I make a variable, synthesize it in appDelegate.m and allocate it in the first function. See below

@synthesize from;

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
    AppDelegate *appDelegate = [[UIApplication sharedApplication]delegate];
    appDelegate.from = [[NSMutableString alloc]init];
    // Override point for customization after application launch.
    return YES;
}

Now you can access it elsewhere if you include appDelegate.h using:

AppDelegate *appDelegate = [[UIApplication sharedApplication]delegate];
appDelegate.from
  • It worked. I end up using a separate view controller per page as it helps me organize it better – Hann Aug 05 '14 at 09:00