Muthu Raj Muthu Raj - 1 month ago 12
iOS Question

getting NSException while passing data from one viewController to another viewController

I am passing a data from one viewController to another viewController. But it is throwing

NSException
.

Here is my code.

viewcontroller.m

NSString *empid1 = [dataDict objectForKey:@"EmployeeId"];
NSLog(@"empid %@",empid1); //it prints 161.
DashBoardViewController *dash = [[DashBoardViewController alloc]initWithNibName:@"DashBoardViewController" bundle:nil];
dash.empid = empid1;


DashBoardViewController.h

@property (strong, nonatomic) NSString * empid;


DashBoardViewController.m

NSString *strURL=[NSString stringWithFormat:@"http://192.168.1.1:8002/api/Case/GetCaseByEmployeeID/?empId=%@",_empid];


It throws data is
nil.NSException
.Any help will be appreciated.

Answer

plz use this you are using storyboard

pass your value like this

 [self performSegueWithIdentifier:@"DashBoardViewController" sender:[dataDict objectForKey:@"EmployeeId"]];

use this method when you use performSegueWithIdentifier

- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
    if ([segue.identifier isEqualToString:@"DashBoardViewController"])
    {
        DashBoardViewController *dash= segue.destinationViewController;
      dash.empid =(NSString *)sender;

    }
}