Question

I'm new to iOS, and I'm looking for a solution to the following situation:

I have 2 view controllers: the first VC has 2 text fields and a button, and the second VC has a "result" text field, which must contain the sum of the 2 text fields in the previous VC. I connected those 2 VCs with a push segue.

The app is ok with the entry data, but it's not making the sum appear in the "result" textField. How can I make the result textField show the sum I want? Code snippets would be great! I'm using Xcode 4.4.1.

Thanks in advance!

Was it helpful?

Solution

Use prepareForSegue:sender:. The segue parameter can give you access to both controllers through the sourceViewController and destinationViewController properties. You should have properties in you source controller that either point to the text fields or their values, so you can get the sum from them. The destination controller should have a property, sum perhaps, that you then set equal to the sum you got from the source controller.

You really should study the View Controller Programming Guide for iOS, this and many other things you need to know are in there.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top