0

I am trying to transfer an NSDictionary from UIViewcontroller to a UIView.
The Dictionary contains the x and y values of a polygon.
The Uiview will plot this polygon.
My problem is that the x y values exist on UIViewcontroller,
they reach the initWithFrame in Uiview,
but can not reach the drawRect in the Uiview.
Please help me.

#import "ViewController.h"
#import "circles_3.h"
#import "draw.h"

@implementation ViewController

@synthesize Core;

- (void)viewDidLoad
{

[super viewDidLoad];
int i;

// Returns NSMutable dictionary with x y points of polygons, some nsstrings and some colors
circles_3 *geo = [circles_3 alloc];
self.Core=[geo updatenum:self.Core];


// Count number of Patches
NSUInteger numObjects = [[self.Core valueForKeyPath:@"Data"] count];

NSArray* filtered=[Core objectForKey:@"Data"];

// Pointer to the UIview class
draw *patch;

// Iterate for all the polygons
for (i=0;i<numObjects;i++)
{
    NSDictionary *data = [filtered objectAtIndex:i];

    // Sent the data to the draw class for plotting
    patch = [[draw alloc] initWithFrame:[[UIScreen mainScreen] bounds] data :data];

    [self.view addSubview:patch];

}
}
@end









 #import <UIKit/UIKit.h>
 #import "ViewController.h"
 #define ARC4RANDOM_MAX      0x100000000
 @interface draw : UIView
  @property  NSDictionary * data;
  - (id)initWithFrame:(CGRect)frame data:(NSDictionary *)Core;
   @end

The UIview class

 #import "draw.h"

  @implementation draw

  @synthesize data;

  - (id)initWithFrame:(CGRect)frame data:(NSDictionary *)Core;
 {
     self = [super initWithFrame:frame];

     if (self)
      {
         self.data=Core;
       }
     return self;
   }

  - (void)drawRect:(CGRect)rect
 {

   // In here i get nil for
    self.data
   ???????????????
    }
Vaki
  • 29
  • 2
  • possible duplicate of [Passing Data between View Controllers](http://stackoverflow.com/questions/5210535/passing-data-between-view-controllers) – Hot Licks Oct 06 '14 at 17:19
  • Make sure that you're not passing `nil` into the `-initWithFrame:data:` method. It could be that the view is loaded before your view controller's data is set up. – Caleb Oct 06 '14 at 17:20
  • @HotLicks Look at the code -- OP appears to be passing the data properly. Also, this is about passing data between a view controller and its view(s), not between two view controllers. I wouldn't call this one a dupe of the other. – Caleb Oct 06 '14 at 17:24
  • @Vaki It's a little weird that you're creating `numItems` views, each covering the whole screen. Also, it'd help if you'd follow the normal Obj-C naming conventions: capitalize class names, lower case for properties and variables. – Caleb Oct 06 '14 at 17:29
  • @Caleb - Except for special cases such as using segues, passing data is passing data. The referenced question covers several different scenarios. – Hot Licks Oct 06 '14 at 17:33
  • Getting nil in this sort of scenario is usually due to one of three causes: 1) The variable simply is never initialized with an object pointer. (Happens quite often.) 2) There are two object instances -- the variable is initialized in one and the reference is done in the other (often one created after the variable was initialized, even). 3) The variable is initialized, but after the reference (due, eg, to the order that operations occur in initializing a view controller). And, of course, one can get a nil due to referencing an object using a nil pointer. – Hot Licks Oct 06 '14 at 17:37

0 Answers0