Passing variables to different view controllers

后端 未结 5 681
有刺的猬
有刺的猬 2021-01-14 22:01

I\'ve searched and searched but nothing has really worked.

I\'m trying to set a textvalue from a text box, into a string or whatever, so that I can call it up later

相关标签:
5条回答
  • 2021-01-14 22:44

    Do you guys think that using the AppDelegate as the holder for one's model is fundamentally wrong? I mean AppDelegate is easily visible to all controllers so it's easy to bind to and get/set it's properties.

    pom

    0 讨论(0)
  • 2021-01-14 22:49

    Spend some time trying to grok the Model View Controller pattern.

    In your case you may be looking to share data between different views sharing a common Model. The Model is the store of your data, in your case the textvalue.

    0 讨论(0)
  • 2021-01-14 22:52

    If you want it in several controllers, then I would think you need to run it through the model?

    0 讨论(0)
  • 2021-01-14 22:53

    You could make an instance variable on the other view controller retain or copy the value before you push/pop the view. For example:

    OpenNextViewController *varNextPageController = [[OpenNextViewController alloc] initWithNibName:@"OpenNextViewController" bundle:nil];
    varNextPageController .textString= self.textString;
    [[self navigationController] pushViewController:varNextPageController animated:YES];
    [varNextPageController release];
    

    In "OpenNextViewController" in this example have an instance variable "textString" that retains or copies (depending on your needs) your text.

    0 讨论(0)
  • 2021-01-14 22:59

    Your question is a bit vague. Could you give any more specifics. It sounds like you want to know:

    1. How to get values from controls. In the case of a text field there should be a text property you can get the value from.

    2. How to share values between controllers. Not sure exactly what you mean. The controller usually orchestrates the sharing of values between different views by using a model as the authoritative version of the data.

    Again, if you can be any more specific we may be able to help more

    0 讨论(0)
提交回复
热议问题