ios - PopupViewController returns null to ViewController -
i pass datepicker.date datepickerpopupviewcontroller sensorvviewcontroller shown below. however, returns me "null". doing wrong? code follows:
#import "datepopoverviewcontroller.h" @interface datepopoverviewcontroller () @end @implementation datepopoverviewcontroller @synthesize datepicker; - (id)initwithnibname:(nsstring *)nibnameornil bundle:(nsbundle *)nibbundleornil { self = [super initwithnibname:nibnameornil bundle:nibbundleornil]; if (self) { // custom initialization } return self; } - (void)viewdidload { [super viewdidload]; // additional setup after loading view nib. datepicker.date=[nsdate date]; } @end #import "sensorviewcontroller.h" @interface sensorviewcontroller () @end // represent button triggers popupviewcontroller -(void)choosedate { if([popovercontroller ispopovervisible]) { [popovercontroller dismisspopoveranimated:yes]; } else { cgrect poprect=cgrectmake (900,1,1,1); //cgrect poprect=cgrectmake (tools.frame.origin.x,tools.frame.origin.y,50,50); popovercontroller.popovercontentsize =cgsizemake(320,216); [popovercontroller presentpopoverfromrect:poprect inview:self.view permittedarrowdirections:uipopoverarrowdirectionup animated:yes]; datepop=[[datepopoverviewcontroller alloc]init]; nsdate *ali= datepop.datepicker.date; nslog(@"%@",ali); } } @end
this code:
cgrect poprect=cgrectmake (900,1,1,1); //cgrect poprect=cgrectmake (tools.frame.origin.x,tools.frame.origin.y,50,50); popovercontroller.popovercontentsize =cgsizemake(320,216); [popovercontroller presentpopoverfromrect:poprect inview:self.view permittedarrowdirections:uipopoverarrowdirectionup animated:yes]; datepop=[[datepopoverviewcontroller alloc]init]; nsdate *ali= datepop.datepicker.date; nslog(@"%@",ali);
should more like:
popovercontroller=[[datepopoverviewcontroller alloc]init]; cgrect poprect=cgrectmake (900,1,1,1); //cgrect poprect=cgrectmake (tools.frame.origin.x,tools.frame.origin.y,50,50); popovercontroller.popovercontentsize =cgsizemake(320,216); [popovercontroller presentpopoverfromrect:poprect inview:self.view permittedarrowdirections:uipopoverarrowdirectionup animated:yes];
and should setup delegate relationship or block callback when user has selected date method called , can do:
nsdate *ali= popovercontroller.datepicker.date; nslog(@"%@",ali);
or, better, popover controller gets date picker , passes parameter callback method / block.
something (typed inline):
in popover:
typedef void (^completionblock) (); @propertty (copy, nonatomic) completionblock completionblock; - (void)dateselected { self.completion(); }
in source controller:
self.popovercontroller.completionblock = ^{ nslog(@"%@", self.popovercontroller.datepicker.date); };
Comments
Post a Comment