user672696
user672696

Reputation: 3

UITextField value between views Objective-C

I have only two views, "1" and "2". "2" contains two UITextFields where I can set numbers. After this, the app does some counting and gives a value. I save this value as a float. So the question is: I want to use that float value in view "1", how can I do this without using the singleton?

Upvotes: 0

Views: 194

Answers (3)

Matt J
Matt J

Reputation: 961

To follow proper MVC guidelines, views should not directly communicate with each other. Instead, they should communicate via an intermediary, such as a UIViewController. Typically, a View is added to the display via a View Controller, so you probably already have one of these. Your controller will obtain the number from View1 and communicate it to View2.

Upvotes: 0

jcane86
jcane86

Reputation: 681

If you have separate view controllers, you could consider doing your calculations on the appDelegate, which is accesible to all view controllers. From there you could pass results to "view1"

Upvotes: 1

Dan Hanly
Dan Hanly

Reputation: 7839

If you have a view controller on that covers both your views, you can share information between them just by saving them into a variable as normal, the variable will be accessible to other functions if it's defined in your .h file. This is ONLY if the same view controller covers both your views.

Upvotes: 0

Related Questions