I have classes *ColorViewController *DrawRectangle
In ColorViewController.h:
#import "DrawRectangle.h"
@interface ColorViewController : UIViewController {
DrawRectangle *DrawRectangle;
}
@property (nonatomic,retain) DrawRectangle *DrawRectangle;
And in DrawRectangle.h:
@interface DrawRectangle : UIView {
CGFloat redc;
}
@property (nonatomic) CGFloat redc;
I have also added the DrawRectangle class in ViewController.xib to one of UIView.
I want to change the value of CGFloat redc from file ColorViewController.m I'm doing it this way:
- (void)viewDidLoad
{
CGFloat myfloat = 1.0;
self.DrawRectangle.redc = myfloat;
I'm calling NSLog with this 'redc' in DrawRectangle, but it says 0.0000000 each time.
How can I replace the value of 'redc' from ViewController? I don't think I need to use NSNotification, there must be easier way if I have the DrawRectangle loaded into ViewController.
Looks like your object hasn't been instantiated yet. Try:
-(void)viewDidLoad {
[super viewDidLoad];
CGFloat myfloat = 1.0;
[drawRectangle setRedc:myfloat];
}
You should also avoid naming your objects the same name as the class as a general programming practice. I Would suggest renaming the object to drawRectangle
.
You also need to hook up your drawRectangle object in your xib
@property (nonatomic, retain) IBOutlet DrawRectangle *drawRectangle;
@synthesize redc;
and @synthesize DrawRectangle;
ColdLogic 2012-04-05 23:10
CGFloat myfloat = 1.0;
NSLog(@"%f", myfloat);
[drawRectangle setRedc:myfloat];` but doesn't work still
< - Konrad Kolasa 2012-04-05 23:14
1.000000000
because you are just outputting the CGFloat
you just create - ColdLogic 2012-04-05 23:15
NSLog(@"Value %f",redc);
Konrad Kolasa 2012-04-05 23:18