1
@implementation ViewController

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


- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}
-(void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
{
    SecondViewController *svc=[segue destinationViewController];
    if ([segue.identifier isEqualToString:@"show"]) {
        svc.scrool=@"dict";
    }
}   

- (IBAction)buttonAction:(id)sender {

    dict= @{@"firstname":@"firstname.textfield.text", @"lastname":@"lastname.textfield.text", @"fullname":@"fullname.textfield.text",@"gender":@"gender.textfield.text",@"country":@"country.textfield.text",@"state":@"state.textfield.text",@"phnumber":@"phnumber.textfield.text",@"email":@"email.textfield.text",@"zipcode":@"zipcode.textfield.text",@"landnumber":@"landnumber.textfield.text"};


 }

can u please anyone give me answer for these need to send these dictionary to another view controller using segues

subbu
  • 31
  • 3
  • 4
    Possible duplicate of [Passing Data between View Controllers](http://stackoverflow.com/questions/5210535/passing-data-between-view-controllers) – Sneha May 04 '17 at 11:48

3 Answers3

1

make this change:

-(void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
{
    SecondViewController *svc=[segue destinationViewController];
    if ([segue.identifier isEqualToString:@"show"]) {
        svc.scrool = dict;
    }
} 

In your code you are passing a string with the value of "dict", and not your dict variable.

Edit: I also want to add that in this code:

dict= @{@"firstname":@"firstname.textfield.text", @"lastname":@"lastname.textfield.text", @"fullname":@"fullname.textfield.text",@"gender":@"gender.textfield.text",@"country":@"country.textfield.text",@"state":@"state.textfield.text",@"phnumber":@"phnumber.textfield.text",@"email":@"email.textfield.text",@"zipcode":@"zipcode.textfield.text",@"landnumber":@"landnumber.textfield.text"};

You are not actually pulling the values from your textfields. Given that you have all of these properties set correctly, you would need to use:

dict= @{@"firstname": firstname.textfield.text, @"lastname": lastname.textfield.text, @"fullname": fullname.textfield.text, @"gender": gender.textfield.text, @"country": country.textfield.text, @"state": state.textfield.text, @"phnumber": phnumber.textfield.text, @"email": email.textfield.text, @"zipcode": zipcode.textfield.text, @"landnumber": landnumber.textfield.text};

Also make sure you have the scrool property in your SecondViewController's .h file:

@property (strong, nonatomic) NSDictionary *scrool;

Wow it has been a while since I have written Obj-c code lol

Jacob Boyd
  • 672
  • 3
  • 19
0

Try this

- (IBAction) buttonAction:(id)sender
{
    [self performSegueWithIdentifier:@"show" sender:sender];
}

-(void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
{
    SecondViewController *svc=[segue destinationViewController];
    if ([segue.identifier isEqualToString:@"show"]) {
        svc.scrool=@"dict";
        svc.dict = @{@"firstname":@"firstname.textfield.text", @"lastname":@"lastname.textfield.text", @"fullname":@"fullname.textfield.text",@"gender":@"gender.textfield.text",@"country":@"country.textfield.text",@"state":@"state.textfield.text",@"phnumber":@"phnumber.textfield.text",@"email":@"email.textfield.text",@"zipcode":@"zipcode.textfield.text",@"landnumber":@"landnumber.textfield.text"};
    }
} 
KKRocks
  • 8,222
  • 1
  • 18
  • 84
0
  • First import another ViewController in current ViewController.

    #import "secViewController.h"
    

Now set the data another view data when prepare for degue method is called.

ViewController.m file

-(void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender{
    secViewController *dest = [segue destinationViewController];
    dest.data = @"test data";
}

Here declare NSString *data as globally in destination ViewController.

secViewController.h

@property NSString *data;

Which one Data receive that print in viewDidLoad() Method.

secViewController.m

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    NSLog(@"%@",self.data);
}
Sakir Sherasiya
  • 1,562
  • 1
  • 17
  • 31