0

My goal is to update a UIView's drawing from a seperate view controller (in a different tab) so I created an outlet for it:

@property (strong,nonatomic) IBOutlet GraphView *graphview; (and synthesized it).

However I cannot connect this outlet to the view I want to access in storyboard. I tried control dragging from the DataController.h file to the the view in storyboard and the other way around and it's not setting.

EDIT

clarifying my main goal that in my tab bar application, I need to access a view inside a scrolview in TAB2 from a view controller inside Tab1 in order to update everytime I add a value to the core data context.

Ayrad
  • 3,996
  • 8
  • 45
  • 86

1 Answers1

1

IBOutlets are Interface Builder Outlets, They are only for objects that are in the view associated with that particular viewController. What exactly are you trying to update?

Hubert Kunnemeyer
  • 2,261
  • 1
  • 15
  • 14
  • My view controller has a button to add an item to core data. When that happens, I want to ask another view (in a seperate tab), to update itself. So I assumed I need an outlet for that. The full scenario is here: http://stackoverflow.com/questions/8695497/is-this-the-correct-way-of-refreshing-the-drawing-in-a-different-view/8698941#8698941 – Ayrad Jan 04 '12 at 08:29
  • The view can't redraw itself until it is asked to appear. You need to save the values/data for your other view. Then when that View is opened load the new data in the viewWillAppear if you want it to be updated immediately upon opening. If your using CoreData then that info should be saved to the store, so you can use a fetchRequest to your ManagedObject to get the data when the view appears and ask the view to update itself when the fetchRequest is finished. – Hubert Kunnemeyer Jan 04 '12 at 18:51
  • I can already fetch the data from the store. My issue is that I need to call drawRect on my CustomView. So I figured I should tell [CustomView drawsetNeedsDisplay:true] or something like that. But the view is inside a scroll view inside a tab. I'm not sure how I can get a reference to it – Ayrad Jan 04 '12 at 21:24
  • 1
    You can get a reference to a ViewController in a tabBarController like this:[self.tabBarController.viewControllers objectAtIndex:0] passing in the index of tab you want.Its a Zero Based index like any other array. – Hubert Kunnemeyer Jan 04 '12 at 21:33
  • Yeap that's what I was looking for: This worked: NSError *error; if (![managedObjectContext save:&error]) { // Handle the error. } UIScrollView *scrollView = [[[self.tabBarController.viewControllers objectAtIndex:2] view].subviews objectAtIndex:0 ]; GraphView *gview = [[scrollView subviews]objectAtIndex:0]; [gview setNeedsDisplay]; – Ayrad Jan 04 '12 at 22:43