0

I am making an App in which i need to pass data between views using button click in Objective-C.

I have created, ViewController.m to pass and DetailController.m to get...

ViewController.m:

   - (IBAction)btnSubmit:(id)sender {

     NSString *name = [txtName text];

     DetailController *view2 = [[[DetailController alloc] 
     initWithNibName:nil  bundle:nil] autorelease];
     [self presentViewController:view2 animated:NO completion:NULL];

      }

DetailController.m

    - (void)viewDidLoad
     {
        [super viewDidLoad];
        // Do any additional setup after loading the view from its nib.

        lblResult.text = [self.detailItem description];
      }

I am not getting the reason why i am not able to pass name value to another view

1
  • lblResult.text = self.detailItem if detailItem is a string Commented Apr 17, 2013 at 5:58

2 Answers 2

6

you forgot to add this line:

view2.detailItem = name;

      (IBAction)btnSubmit:(id)sender {

         NSString *name = [txtName text];

            DetailController *view2 = [[[DetailController alloc] 
            initWithNibName:nil bundle:nil] autorelease];
            view2.detailItem = name;
            [self presentViewController:view2 animated:NO completion:NULL];

  }
Sign up to request clarification or add additional context in comments.

Comments

1
DetailController *view2 = [[[DetailController alloc] 
     initWithNibName:nil  bundle:nil] autorelease];
view2.detailItem = self.yourValue;    
[self presentViewController:view2 animated:NO completion:NULL];

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.