Reputation: 60
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
Upvotes: 0
Views: 125
Reputation: 2051
DetailController *view2 = [[[DetailController alloc]
initWithNibName:nil bundle:nil] autorelease];
view2.detailItem = self.yourValue;
[self presentViewController:view2 animated:NO completion:NULL];
Upvotes: 1
Reputation: 1609
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];
}
Upvotes: 6