ios - Pass double to Viewcontroller then to UIView -
full code
viewcontroller.h
#import <uikit/uikit.h> @interface viewcontrollerimage : uiviewcontroller { iboutlet uilabel *datum; iboutlet uilabel *debug; } @property (nonatomic, assign) double thicknessvalue1; @property (nonatomic, assign) double capwidthvalue1; @end
viewcontroller.m
- (void)viewdidload { [super viewdidload]; // additional setup after loading view. [datum settransform:cgaffinetransformmakerotation(m_pi / 2)]; nsstring *value = [[nsstring alloc] initwithformat:@"%f", self.thicknessvalue1]; debug.text = value; draw2d *myview = [[draw2d alloc]initwiththickness: self.thicknessvalue1 andcapwidth: self.capwidthvalue1]; nslog(@"first logs"); nslog(@"%f",myview.thicknessvalue2); nslog(@"%f",myview.capwidthvalue2); nslog(@"end first logs"); }
draw2d.h #import
@interface draw2d : uiview - (id)initwiththickness:(double)thickness andcapwidth:(double)capwith; @property (nonatomic, assign) double thicknessvalue2; @property (nonatomic, assign) double capwidthvalue2; @end
draw2d.m
#import <uikit/uikit.h> @interface draw2d : uiview - (id)initwiththickness:(double)thickness andcapwidth:(double)capwith { self = [super init]; if(self) { thicknessvalue2 = self.thicknessvalue2; capwidthvalue2 = self.capwidthvalue2; nslog(@"second logs"); nslog(@"%f",thicknessvalue2); nslog(@"%f",capwidthvalue2); nslog(@"end second logs"); } return self; } @end
i have provided full code second view controller uiview, hope can see going wrong. or explain me i'm doing wrong.
i'm adding answer previous long.
dude physically can not more this, not complex @ all. i'm sorry not finding info online creating object not true, quite literally everywhere. did learn it?
2 things note.
naming convention says classes start capital e.g.
draw2d
needsdraw2d
you shouldn't naming variables xxx1, xxx2 etc. if same thing, name them same thing. doesn't matter if different classes.
code:
in viewcontroller:
- (void)viewdidload { [super viewdidload]; nslog(@"before init"); draw2d *myview = [[draw2d alloc] initwithframe:cgrectmake(0, 0, 320, 320) thickness:15.0 capwidth:17.5]; nslog(@"after init"); [self.view addsubview:myview]; nslog(@"after placing on superview @ x= 0, y = 0, width = 320, height = 320"); }
draw2d.h
#import <uikit/uikit.h> @interface draw2d : uiview @property (nonatomic, assign) double thickness; @property (nonatomic, assign) double capwidth; - (id)initwithframe:(cgrect)frame thickness:(double)thickness capwidth:(double)capwidth; @end
draw2d.m
#import "draw2d.h" @implementation draw2d - (id)initwithframe:(cgrect)frame { self = [super initwithframe:frame]; if (self) { // initialization code } return self; } - (id)initwithframe:(cgrect)frame thickness:(double)thickness capwidth:(double)capwidth { self = [super initwithframe:frame]; if(self) { // left side property in .h // right side parameters passed method self.thickness = thickness; self.capwidth = capwidth; } return self; } - (void)drawrect:(cgrect)rect { nslog(@"passed in thickness: %f", self.thickness); nslog(@"passed in capwidth: %f", self.capwidth); } @end
console:
2014-04-16 09:23:23.613 before init 2014-04-16 09:23:23.613 after init 2014-04-16 09:23:23.613 after placing on superview @ x= 0, y = 0, width = 320, height = 320 2014-04-16 09:23:23.615 passed in thickness: 15.000000 2014-04-16 09:23:23.616 passed in capwidth: 17.500000
Comments
Post a Comment