mirror of
https://github.com/purplecabbage/phonegap-plugins.git
synced 2026-04-24 03:00:11 -04:00
Fixed a few minor errors with releasing to early. Also ensure the JS returns the date to the PG JS client
This commit is contained in:
@@ -26,22 +26,32 @@
|
||||
|
||||
#pragma mark - Public Methods
|
||||
|
||||
- (PGPlugin *)initWithWebView:(UIWebView *)theWebView
|
||||
{
|
||||
self = (DatePicker *)[super initWithWebView:theWebView];
|
||||
|
||||
NSLog(@"DatePicker refs: %i, datePickerSheet refs: %i, dataPicker refs: %i", [self retainCount], [_datePickerSheet retainCount], [_datePicker retainCount]);
|
||||
|
||||
[self initActionSheet:self];
|
||||
|
||||
[self initActionSheetCloseButton:self.datePickerSheet title:@"Close" target:self action:@selector(dismissActionSheet:)];
|
||||
|
||||
return self;
|
||||
}
|
||||
|
||||
- (void)show:(NSMutableArray*)arguments withDict:(NSMutableDictionary*)options
|
||||
{
|
||||
if (isVisible) {
|
||||
return;
|
||||
}
|
||||
|
||||
[self initActionSheet:self];
|
||||
|
||||
[self initActionSheetCloseButton:self.datePickerSheet title:@"Close" target:self action:@selector(dismissActionSheet:)];
|
||||
|
||||
|
||||
UIDatePicker *datePickerInstance = [[self createDatePicker:CGRectMake(0, 40, 0, 0) options:options] retain];
|
||||
self.datePicker = datePickerInstance;
|
||||
[self.datePickerSheet addSubview:datePickerInstance];
|
||||
[datePickerInstance release];
|
||||
|
||||
[self.datePickerSheet showInView:[[super webView] superview]];
|
||||
[self.datePickerSheet setBounds:CGRectMake(0, 0, 320, 485)];
|
||||
|
||||
isVisible = YES;
|
||||
}
|
||||
@@ -50,6 +60,19 @@
|
||||
[self.datePickerSheet dismissWithClickedButtonIndex:0 animated:YES];
|
||||
}
|
||||
|
||||
- (void) onMemoryWarning
|
||||
{
|
||||
// It could be better to close the datepicker before the system
|
||||
// clears memory. But in reality, other non-visible plugins should
|
||||
// be tidying themselves at this point. This could cause a fatal
|
||||
// at runtime.
|
||||
if (isVisible) {
|
||||
return;
|
||||
}
|
||||
|
||||
[self release];
|
||||
}
|
||||
|
||||
- (void)dealloc
|
||||
{
|
||||
[_datePicker release];
|
||||
@@ -60,28 +83,24 @@
|
||||
|
||||
#pragma mark - UIActionSheetDelegate methods
|
||||
|
||||
- (void)willPresentActionSheet:(UIActionSheet *)actionSheet
|
||||
{
|
||||
[self.datePickerSheet setBounds:CGRectMake(0, 0, 320, 485)];
|
||||
}
|
||||
|
||||
- (void)actionSheet:(UIActionSheet *)actionSheet willDismissWithButtonIndex:(NSInteger)buttonIndex
|
||||
{
|
||||
NSString* jsCallback = [NSString stringWithFormat:@"window.plugins.datePicker._dateSelected(\"%i\");", (int)[self.datePicker.date timeIntervalSince1970]];
|
||||
NSLog(@"Date: %@", self.datePicker);
|
||||
NSLog(@"%f", [self.datePicker.date timeIntervalSince1970]);
|
||||
[super writeJavascript:jsCallback];
|
||||
}
|
||||
|
||||
- (void)actionSheet:(UIActionSheet *)actionSheet didDismissWithButtonIndex:(NSInteger)buttonIndex
|
||||
{
|
||||
isVisible = NO;
|
||||
[self release];
|
||||
}
|
||||
|
||||
#pragma mark - Private Methods
|
||||
|
||||
- (void)initActionSheetCloseButton:(UIView *)parentView title:(NSString *)title target:(id)target action:(SEL)action
|
||||
{
|
||||
UISegmentedControl *closeButton = [[UISegmentedControl alloc] initWithItems:[NSArray arrayWithObject:title]];
|
||||
UISegmentedControl *closeButton = [[UISegmentedControl alloc] initWithItems:[NSArray arrayWithObject:title]];
|
||||
|
||||
closeButton.momentary = YES;
|
||||
closeButton.frame = CGRectMake(260, 7.0f, 50.0f, 30.0f);
|
||||
|
||||
Reference in New Issue
Block a user