Pastebin is 300% more awesome when you are logged in. Sign Up, it's FREE!
Guest

Passing object from controller to a view

By: a guest on Feb 27th, 2012  |  syntax: None  |  size: 1.21 KB  |  hits: 23  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. #import "PolygonShape.h"
  2.  
  3. @interface CustomView : UIView {
  4.     IBOutlet PolygonShape *polygon;
  5. }
  6. - (NSArray *)pointsForPolygonInRect:(CGRect)rect numberOfSides:(int)numberOfSides;
  7.  
  8. @end
  9.        
  10. #import <UIKit/UIKit.h>
  11. #import <Foundation/Foundation.h>
  12. #import "PolygonShape.h"
  13. #import "PolygonView.h"
  14.  
  15. @interface Controller : NSObject {
  16.     IBOutlet UIButton *decreaseButton;
  17.     IBOutlet UIButton *increaseButton;
  18.     IBOutlet UILabel *numberOfSidesLabel;
  19.     IBOutlet PolygonShape *polygon;
  20.     IBOutlet PolygonView *polygonView;
  21. }
  22. - (IBAction)decrease;
  23. - (IBAction)increase;
  24. - (void)awakeFromNib;
  25. - (void)updateInterface;
  26. @end
  27.        
  28. #import "PolygonShape.h"
  29.  
  30. @interface CustomView : UIView {
  31.     IBOutlet PolygonShape *polygon;
  32. }
  33.  
  34. @property (readwrite, assign) PolygonShape *polygon;
  35.  
  36. - (NSArray *)pointsForPolygonInRect:(CGRect)rect numberOfSides:(int)numberOfSides;
  37.  
  38. @end
  39.        
  40. @implementation CustomView
  41.  
  42. @synthesize polygon;
  43.  
  44. ...
  45.  
  46. @end
  47.        
  48. - (void)awakeFromNib {
  49.     // configure your polygon here
  50.     polygon = [[PolygonShape alloc] initWithNumberOfSides:numberOfSidesLabel.text.integerValue minimumNumberOfSides:3 maximumNumberOfSides:12];
  51.     [polygonView setPolygon:polygon];
  52.     NSLog (@"My polygon:  %@", [polygon description]);
  53. }