I have a main view controller that loads some data from api, from there I move to another screen which shows details for a particular deal. I want to go back to the main controller, but when I use prepareForSegue
, it goes back to the main controller, but it loads the data again making an api call. I want to retain the state of the main controller.
Please help me as how to retain the state of a view controller and how to segue from the 2nd controller to main controller without loading it again.
- (void)viewDidLoad
{
[super viewDidLoad];
[self FetchDeals];
[self Getdeals];
}
The fetch deal method makes an api call and getdeals populates it into a tableview.
-(void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
{
if ([[segue identifier] isEqualToString:@"Dealdetail"])
{
//NSLog(@"New controller");
DealDetailController *detail = (DealDetailController *)[segue destinationViewController];
detail.detailimage = imagepath;
}
}
DealDetailController is the second view controller from where I come back to the main control.
Code in DealDetailController:
-(void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
{
MainappViewController *maincontrol = (MainappViewController *)[segue destinationViewController];
}