Note that there are some explanatory texts on larger screens.

plurals
  1. POMultiview app. cannot change text field values
    text
    copied!<p>hey guys i'm making an app that has 2 views. the first view is where the user inputs the numbers and when they hit calculate button.. its takes them to a new view where the answer is displayed on a textfield. the calculation is handled by a different file. "calc.h " and "calc.m" </p> <p>this is the main view files (the view where the user enters the numbers ) </p> <pre><code>#import &lt;UIKit/UIKit.h&gt; @interface test2ViewController : UIViewController { IBOutlet UITextField *num1; //input number 1 IBOutlet UITextField *num2; // input number2 } @property (nonatomic,retain) UITextField *num1; @property(nonatomic, retain)UITextField *num2; -(IBAction)calculate:(id)sender; //the calculate button -(IBAction)exit:(id)sender; @end </code></pre> <p>the answer is displayed in a different view that shows up when the user hits the calculate button. below is the code for that !</p> <pre><code>#import "test2ViewController.h" #import "answer.h" #import "calculate.h" @implementation test2ViewController @synthesize num1,num2; -(IBAction)calculate:(id)sender{ calculate *testclass = [[calculate alloc]init]; answer *view = [[answer alloc]initWithNibName:nil bundle:nil]; [self presentModalViewController:view animated:YES]; int i = [[num1 text] intValue]; testclass.number1 = i; int j = [[num2 text] intValue]; testclass.number2 = j; [testclass calc]; } </code></pre> <p>".h" file of the view that displays the answer</p> <pre><code>#import &lt;UIKit/UIKit.h&gt; @interface answer : UIViewController { IBOutlet UITextField *text;//textfield to display answer } @property(nonatomic,retain) UITextField *text; -(IBAction)back:(id)sender; @end </code></pre> <p>".m" file </p> <pre><code>#import "answer.h" #import "test2ViewController.h" #import "calculate.h" @implementation answer @synthesize text; -(IBAction)back:(id)sender{ test2ViewController *view = [[test2ViewController alloc]initWithNibName:nil bundle:nil]; [self presentModalViewController:view animated:YES]; } </code></pre> <p>the next is an objective c class file that does the calculation. it has one function that does the calculation and here is the ".h" and ".m" file ".h"</p> <pre><code>#import &lt;Foundation/Foundation.h&gt; @interface calculate : NSObject { int number1; int number2; NSString *ans; } @property int number1; @property int number2; @property (nonatomic , retain) NSString *ans; -(void)calc; @end </code></pre> <p>".m"</p> <pre><code>#import "calculate.h" #import "answer.h" #import "test2ViewController.h" @implementation calculate @synthesize number1,number2,ans; -(void)calc{ int i = number1 + number2; answer *ans1 = [[answer alloc]init]; ans = [NSString stringWithFormat:@"%d",i]; ans1.text.text = ans; } @end </code></pre> <p>so as you can see the above function calculates the answer..puts it into a string and sets that to the textfield. but the textfield doesn't show anything..so the problem here is that i cannot access the textfield even though i created an object from it....</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload