1

I am still new to iOS development and I wanted to know how to accomplish something. What I have is s UIViewController objects FirstController and SecondController. In the NIB file for FirstController I have a UITextField. In the NIV file for SecondController I have a UILabel.

What I want to do is update the UILabel with a new value as I update the UITextVew. So far, I have the following in my FirstController:

    - (IBAction)tbxName_EditingChanged:(id)sender;

In the SecondController I have the label in an Outlet Collection like so:

    @property (retain, nonatomic) IBOutletCollection(UILabel) NSArray *lblName;

Now, I have made the collection because I intend, in the future, to add more labels that will need to be changed and have all have the same value.

So, what I was thinking that I have to do is place a reference of my SecondController into my FirstController so that I can then run a custom 'update' method. Something like this:

    FirstController *viewController1 = [[[FirstController alloc] initWithNibName:@"FirstController" bundle:nil] autorelease];
    SecondController *viewController2 = [[[SecondController alloc] initWithNibName:@"SecondController" bundle:nil] autorelease];
    viewController1.secondView = viewController2;
    // do the rest to load the views...

Now, I have learned that a lot of the stuff I have learned, in .net., is not the way you do things in Objective C. I was wondering if this is what I have to do, or is there another way that I am not finding with Google?

Thanks for any help, and I hope that I explained this clearly enough.

Andrew Riebe
  • 411
  • 7
  • 17

1 Answers1

3

Solving problems like these in a predictable, proven way is the whole point of the Model-View-Controller design pattern. The point is, you want the first UIViewController to update the model, which will signal the second UIViewController to update its view.

I'd suggest having a model somewhere. Either by using a singleton, first initialized in the app delegate, or core data, which is a little more advanced but very powerful.

Community
  • 1
  • 1
john
  • 3,043
  • 5
  • 27
  • 48