1

I have a MainController, it creates an object(say polygon), a controller(say,polygonViewController). PolygonViewController has two outlets:

IBOutlet Polygon* aPolygon;
IBOutlet UILabel* numOfSidesLabel;

it mediates Polygon and PolygonViewController.xib file.

How do I make sure the PolygonViewController's aPolygon is the same(instance) as polygon created in mainController?

I tried to add @property Polygon* aPolygon; to PolygonViewController then in MainController I did polygonViewController.aPolygon = polygon; However, aPolygon in PolygonViewController awakeFromNib method is always null.

kennytm
  • 510,854
  • 105
  • 1,084
  • 1,005
Michael Z
  • 4,534
  • 4
  • 21
  • 27
  • Some code pieces would help here.... Why are you declaring an IB outlet for aPolygon when you are assigning it the mainController's Polygon object? As such I don't there is a mechanism to make two Polygon objects declared in two different XIB files to be the same object. – Deepak Danduprolu Feb 06 '10 at 06:13
  • Hi Deepak: Thanks for your help. The Polygon object in MainController is not prefixed with IBOutlet, so it is not in an XIB file. In general, what is the approach if i want to assign my controller class an object created in another class? – Michael Z Feb 07 '10 at 00:48

1 Answers1

1

Have you tried to use a singleton object?

You can make your aPolygon class to be a singleton object so, you will be always working with the same object in as many viewControllers as you want to use it.

Take a look at: http://developer.apple.com/Mac/library/documentation/Cocoa/Conceptual/CocoaFundamentals/CocoaObjects/CocoaObjects.html#//apple_ref/doc/uid/TP40002974-CH4-SW32

Hope this will help you!

Cheers,
VFN

vfn
  • 6,026
  • 2
  • 34
  • 45