-1

I have a simple application with the following structure:

  • 'A': Standalone view controller with a WebView
  • 'B': Navigation controller
  • 'C': Root View Controller in 'B', a TableView of all stores

When the URL of the WebView in 'A' becomes something specific (http://www.mysite.com/store), I need to:

  1. Push to 'C'
  2. Send a string to be used in 'C'

How can I achieve this?

carloabelli
  • 4,289
  • 3
  • 43
  • 70
AdamTheRaysFan
  • 175
  • 2
  • 9
  • possible duplicate of [Passing Data between View Controllers](http://stackoverflow.com/questions/5210535/passing-data-between-view-controllers) – Hot Licks May 05 '14 at 03:50
  • probably you need to implement the _model-layer_ in you applciation properly, if you have faced such structural issue... – holex May 05 '14 at 06:53

1 Answers1

0
Here you can do with delegate methods   

// This is your root ViewController to call delegate methods

#import "ThirdViewController.h"
#import "SecondViewController.h"
 @interface ViewController ()<ThirdViewControllerDelegate>
  @end

@implementation ViewController
 #pragma mark -
 #pragma mark ThirdViewController Delegate Method

// Implementation of delegate methods in your Root ViewController

-(void)didSelectValue:(NSString *)value{
    NSLog(@"%@",value);
}
// Pass the last Vc delegate to the next ViewController
-(void)gotoSeconddVc{
    SecondViewController *vc2=[[SecondViewController alloc]init];
    vc2.lastDelegate=self;
    [self.navigationController pushViewController:vc2 animated:YES];
}


 #import "ThirdViewController.h"
     @interface SecondViewController : UIViewController
        @property(nonatomic,retain) id <ThirdViewControllerDelegate> lastDelegate;
        @end

-(void)gotoThirdVc{
    ThirdViewController *vc3=[[ThirdViewController alloc]init];
    vc3.delegate=self.lastDelegate;
    [self.navigationController pushViewController:vc3 animated:YES];
}

Implementation of last viewcontroller

@implementation ThirdViewController


-(void)btnDoneClicked{
    [self.navigationController popToRootViewControllerAnimated:YES];
    [self.delegate didSelectValue:strValue]; //call delegate methods here
}
Sunny Shah
  • 12,990
  • 9
  • 50
  • 86