Reputation: 57
I'm not sure if I have my view controller in my storyboard
file connected to my view correctly but here's a breakdown of the setup - I'm using xcode 5
:
One view controller using custom class CICBoostGaugeViewController
(configured in identity inspector).
One view using custom class CICGaugeBuilder
(configured in identity inspector in storyboard file).
The CICGaugeBuilder
class draws a gauge and sets the properties of the gauge in an init method. When I run this setup in the simulator the gauge appears correctly based on the initialized gauge parameters in CICGaugeBuilder
. No problems so far.
My issue is when I create an instance of the CICGaugeBuilder
class in my view controller and set the properties, they do not show up when I run it in the sim, only the values initialized in the CICGaugeBuilder
class are applied.
CICBoostGaugeViewController.h
#import <UIKit/UIKit.h>
#import "CICGaugeBuilder.h"
@class CICGaugeBuilder;
@interface CICBoostGaugeViewController : UIViewController{
CICGaugeBuilder *boostGauge;
}
@property (nonatomic, retain) IBOutlet CICGaugeBuilder *boostGauge;
@end
CICBoostGaugeViewController.m
#import "CICBoostGaugeViewController.h"
#import "CICGaugeBuilder.h"
@interface CICBoostGaugeViewController ()
@end
@implementation CICBoostGaugeViewController
@synthesize boostGauge;
- (void)viewDidLoad
{
[super viewDidLoad];
self.boostGauge.minGaugeNumber = 0;
self.boostGauge.maxGaugeNumber = 25;
self.boostGauge.gaugeLabel = @"Boost/Vac";
self.boostGauge.incrementPerLargeTick = 10;
self.boostGauge.tickStartAngleDegrees = 135;
self.boostGauge.tickDistance = 270;
self.boostGauge.menuItemsFont = [UIFont fontWithName:@"Helvetica" size:14];
self.boostGauge.value = 10;
}
- (void)viewDidUnload
{
//self.boostGauge = nil;
}
- (void)didReceiveMemoryWarning
{
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
@end
This is the initialization method in the CICGaugeBuilder class:
self.minGaugeNumber = 0;
self.maxGaugeNumber = 100;
self.gaugeType = 2;
self.gaugeLabel = @"Boost/Vac";
self.incrementPerLargeTick = 10;
self.tickStartAngleDegrees = 135;
self.tickDistance = 270;
self.menuItemsFont = [UIFont fontWithName:@"Helvetica" size:14];
Note that the maxGaugeNumber of 100 is retained when run in the simulator. The gauge draws correctly, but the problem is the object instance in the view controller is not used. I've tried [self.boostGauge SetNeedsDisplay]
and it did not work.
In my storyboard file the view controller does not have any referencing outlets. I think this needs to be connected to the app delegate but I'm not sure. Dragging
the view controller to the app delegate does not allow a connection to be made.
Here is the CICAppDelegate.h file:
#import <UIKit/UIKit.h>
@class CICBoostGaugeViewController;
@interface CICAppDelegate : UIResponder <UIApplicationDelegate>{
UIWindow *window;
CICBoostGaugeViewController *viewController;
}
@property (nonatomic, retain) IBOutlet UIWindow *window;
@property (nonatomic, retain) IBOutlet CICBoostGaugeViewController *viewController;
@end
Upvotes: 2
Views: 484
Reputation: 4561
As I go through you App,I found.
After calling [self.boostGauge SetNeedsDisplay]
will not make any kind of effect because:
SetNeedsDisplay
calls the - (void)drawRect:(CGRect)rect
method of CICGaugeBuilder Class
and
- (void)drawRect:(CGRect)rect
{
CGRect innerFrame;
// self.value = 0;
[self initializeGauge];
}
here you again calling initialize method and initialise method will again set value to initial value. ULTIMATELY NO EFFECT.
Most importantly you call value using
CICAppDelegate *ap=(CICAppDelegate *)[[UIApplication sharedApplication]delegate];
ap.guage.value=50;
Take a object reference of CICGaugeBuilder Class
in appDel.
Add following to initialiseGuageMethod
CICAppDelegate *ap=(CICAppDelegate *)[[UIApplication sharedApplication]delegate];
ap.guage=self;
Upvotes: 1