0

I have a UITabBar Controller having three view controller. I am trying to refresh my two view controller which are map view controller and tableview controller; from third view controller with an action of slide. Here what i have tried:

- (IBAction)actionMySlider:(id)sender{
    NSNumberFormatter* numberFormatter = [[NSNumberFormatter alloc] init];
    [numberFormatter setFormatterBehavior: NSNumberFormatterBehavior10_4];
    [numberFormatter setNumberStyle: NSNumberFormatterDecimalStyle];
    NSString *numberString = [numberFormatter stringFromNumber: [NSNumber numberWithInteger: mySlider.value]];
    MetreLabel.text = [NSString stringWithFormat:@"Yarı Çap(Re): %@(m)",numberString];
   [(AppDelegate *)[[UIApplication sharedApplication] delegate] setVariable:[NSString stringWithFormat:@"%f",mySlider.value]];


   ViewController1 *VC1=[[ViewController1 alloc]init];
    [VC1 viewDidLoad];
    ViewController2 *VC2 = [[ViewController1 alloc]init];
    [VC2 viewDidLoad];

}

Thank you for your answers.

EDIT According to answers my approach is implementing a for loop at my TabBar.m. But i have some issues while implementing this.

for (UIViewController *v in self.tabBar.viewControllers)
{
     UIViewController *vc = v;

     if ([v isKindOfClass:[UINavigationController class])
     {
         vc = [v visibleViewController];
     }

     if ([vc isKindOfClass:[MyViewController class]])
     {
          MyViewController *myViewController = vc;
          [vc doSomething];
     }
}
  1. problem: what should i write instead of viewcontrollers at self.tabBar.viewControllers. I could not figure out that.
  2. problem: after i implement that for loop in a method in TabBar.m, will i be able to reach my viewcontrollers from another viewcontroller via calling that method?
user2393702
  • 109
  • 2
  • 8
  • Why don't you just put the initialization code in viewDidAppear? Then it will be called every time `VC1` and `VC2` appear on the screen – Evan Layman May 22 '13 at 22:38

1 Answers1

0

You are allocating a new instance of both ViewController1 and ViewController2 in the actionMySlider method. They are not the same as the view controllers in your tab bar controller.

Try to access the view controller from the tab bar itself. The answer found here will do:

UITabBarController - How to access a view controller?

And you should try to take those lines of code that you want to execute in ViewController1 and ViewController2 after the slider value change out from the viewDidLoad and make them separate methods. Then you can just call those methods without calling the entire viewDidLoad.

Community
  • 1
  • 1
Valent Richie
  • 5,226
  • 1
  • 20
  • 21