I’m new to objective-c programming and I stuck.
I have uislider in my viewcontroller and float variable in header file of viewcontroller.
I also have a new class which changes look of my second view, I overwritten drawRect.
I simply take value of slider.value and save it in my float variable then I try to access float variable in my class because this variable defines width of lines which i want to draw.
header file of my view controller
@interface ViewController : UIViewController
{
float lineWidth;
}
@property float lineWidth;
-(float)changingline;
@end
viecontroller.m //sliderForLine = UISlider
- (IBAction)valuechangedForLine:(UISlider *)sender
{
float sliderValue = sliderForLine.value;
lineWidth = sliderValue;
[self changingline];
}
-(float)changingline
{
NSLog(@"%f", lineWidth);
return lineWidth;
}
NSLog says there is some value in lineWidth
class which specifies how the second UIView should looks like
#import "ViewController.h"
ViewController *oldView = [[ViewController alloc] init];
CGContextSetLineWidth(ctx, oldView.lineWidth);
NSLog(@"%f",oldView.lineWidth);
and here, in second class, NSLog says always 0.
I’m confused, I don’t even know now why I’m using -(void)changeling 🙂
All I know is that I’m missing the main point how to pass values between classes, can somebody explain me what I’m doing wrong?
Thanks in advance :]
You NEED (not want) a delegate for this. Try something like this:
header file of my view controller
//.m
Then all you need to do is conform to the protocol with a pair of these <> and implement the required method.
Also, rename your iVar with an underscore (so, instead of
lineWidth, use_lineWidth) then@synthesize lineWidth = _lineWidth