NimbleKit - fast iOS app development

Obj-c/js mix Date Picker

Ask questions and share your skills here

Obj-c/js mix Date Picker

Postby jbardi » Sat Jul 18, 2009 12:01 pm

I know the Date Picker is on the list of things to add in future releases of Nimblekit, but in the mean time, does anyone know how I could go about putting the Date Picker on one of my pages (preferably) or if not, at least popping it up over a page using my own obj-c class file?

I have mixed obj-c/js now on a few parts of my Applicaiton, but I can't wrap my head around bringing the Date Picker in, as NimbleKit uses .html files for its pages, I can't seem to find out how to bring it into a page or over the top of one of my .html pages rather than using window, frame, subview, etc like I see in the obj-c Date Picker examples on Apple's site.
User avatar
jbardi
 
Posts: 141
Joined: Fri Jul 17, 2009 8:01 am

Re: Obj-c/js mix Date Picker

Postby sunny » Sat Jul 18, 2009 1:00 pm

when you use obj-c/js mix every time you call CallNKitAction method
-setWebView is called, so when you call your init you can addSubView to webView and save the reference somehow, maybe in dictionary with key "currentPage"
[dict setObject:datePicker forKey:currentPageName];

to pass value back just call stringByEvaluatingJavascriptString (if I did not do mistake writing this big-big word) from webView.
int value = 76;
[webView stringByEvaluatingJavascriptString:[NSString stringWithFormat:@"myJsCallback(%d)", value]];
User avatar
sunny
Staff
 
Posts: 2666
Joined: Sat May 30, 2009 5:18 am
Location: Palo Alto, California

Re: Obj-c/js mix Date Picker

Postby jbardi » Thu Aug 06, 2009 6:04 am

Sunny, I am terribly sorry and I don't mean to beat a dead horse here, but I have almost gotten the DateTime picker to work. Using your sample "code_mix.zip" file, I was able to adapt it from the Alert window to displaying my datepicker. I have been able to display it and position it where I want it with the following code:

Code: Select all
- (void)showMyDatePicker
{

    UIDatePicker *datePicker = [[UIDatePicker alloc] initWithFrame:[_webView bounds]];
    datePicker.autoresizingMask = UIViewAutoresizingFlexibleWidth;
    datePicker.frame = CGRectMake(0, 156, 320, 216);
    [_webView addSubview:datePicker];
    [datePicker release];

}

datepicker.png
datepicker.png (80.33 KiB) Viewed 1789 times

But that is as far as I have gotten. And I know there is probably some lines above that are wrong or not necessary, but it works, so I didn't want to mess with it. However, I can not for the life of me figure out how to then get the date sent back to javascript. I have taken your original delegate code block from your "code_mix.zip" alert example:

Code: Select all
#pragma mark -
#pragma mark UIAlertViewDelegate

- (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex
{
   [self._webView performSelectorOnMainThread:@selector(stringByEvaluatingJavaScriptFromString:) withObject:[NSString stringWithFormat:@"clickedButton('%d')", buttonIndex] waitUntilDone:NO];
}

and tried to change it for the datepicker, but no matter what I tried, I could not figure out what to do next, so here is the delegate block without any code in it.

Code: Select all
#pragma mark -
#pragma mark UIPickerViewDelegate

- (void)pickerView:(UIPickerView *)pickerView
{
   // DONT KNOW WHAT TO PUT HERE
}

I don't know what code to put in the block nor how I would trigger that code in the first place after selecting the date from the scroll wheels. If you could please give me a starting point to launch from I would greatly appreciate it. My Company was finally approved by Apple earlier today and I have paid my $99 to them and finally got a chance to provision my phone for testing outside of the simulator, but this datepicker is the last thing holding me back from my App being ready for submission.

Once I get this figured out, I will be purchasing my $99 Nimblekit license and submitting to the App store (after 1.5 is out of beta actually), but it all depends on if I can figure out the datepicker issue.

Thanks again for all of the help you have given the entire community. You have opened the door to those of us having minor c/obj-c knowledge as well as those with no knowledge at all to get our hands into iPhone development.
User avatar
jbardi
 
Posts: 141
Joined: Fri Jul 17, 2009 8:01 am

Re: Obj-c/js mix Date Picker

Postby sunny » Thu Aug 06, 2009 10:27 am

So I modified you code a little and made a date picker which you can modify the way you want :)
glad I could help! :)
Attachments
DatePicker.zip
(19.4 KiB) Downloaded 275 times
User avatar
sunny
Staff
 
Posts: 2666
Joined: Sat May 30, 2009 5:18 am
Location: Palo Alto, California

Re: Obj-c/js mix Date Picker

Postby jbardi » Thu Aug 06, 2009 5:33 pm

Sunny, you have saved me hours of frustration... your example worked perfectly inside my project... I don't know how to thank you. All I need to do now is some minor tweaks to my code and when 1.5 is out of beta, I'll be Nimblekit registered and submitting to the App store. WOO HOO :mrgreen:

Part of it is that I have to wait a little bit... just paid $99 to Apple, so waiting for the bank account to rebound :shock:
User avatar
jbardi
 
Posts: 141
Joined: Fri Jul 17, 2009 8:01 am

Re: Obj-c/js mix Date Picker

Postby brass » Thu Aug 13, 2009 3:11 pm

hey i have tried to get this to work in one of my apps. I can get the sample files you put up to work either and i am running the current beta version of 1.5.

I need the date pick to assign picked date to a var then take that var and pick image depending on the date picked. Sounds simple but i can't get it to work. Anyone shed some light?
brass
 
Posts: 64
Joined: Mon Aug 03, 2009 9:00 pm

Re: Obj-c/js mix Date Picker

Postby sunny » Thu Aug 13, 2009 3:21 pm

first you show date picker
in example:
Code: Select all
CallNKitAction("showMyDatePicker?className=MyDatePickerController");

then you wait for user input having button to finish picking date and when it's pressed you call:
Code: Select all
// get date
var date = CallNKitAction("getDateFromDatePicker?className=MyDatePickerController&sync=yes");
// hide datepicker
CallNKitAction("hideMyDatePicker?className=MyDatePickerController");
// then check date
// and show your image depending on it
User avatar
sunny
Staff
 
Posts: 2666
Joined: Sat May 30, 2009 5:18 am
Location: Palo Alto, California

Re: Obj-c/js mix Date Picker

Postby brass » Thu Aug 13, 2009 4:49 pm

i am trying this out in your sample code but i cant get the date picker to show when the "show picker" link is clicked. i have made no changes to the code you up loaded
brass
 
Posts: 64
Joined: Mon Aug 03, 2009 9:00 pm

Re: Obj-c/js mix Date Picker

Postby sunny » Thu Aug 13, 2009 4:54 pm

if the sample project is not working that means you not properly updated nimblekit. now when nimblekit is out of beta try downloading version 1.5 from http://www.nimblekit.com and after that try again sample project, this has to work. Also if it does not try emptying Xcode cache files and "clean" you application target (main menu Build->Clean All Tagets)
User avatar
sunny
Staff
 
Posts: 2666
Joined: Sat May 30, 2009 5:18 am
Location: Palo Alto, California

Re: Obj-c/js mix Date Picker

Postby brass » Thu Aug 13, 2009 4:59 pm

my fault, been following closely for some time now, didn't realize 1.5 was out. Thanks man for the help. I will test the code now. thanks again


it is working, how can i just make the date picker pick only the day, i am not concerned with time. Just need it to drop date back into code in format of 8132009. file name and tomorrow for 8142009. filename, etc etc. is this possible?
brass
 
Posts: 64
Joined: Mon Aug 03, 2009 9:00 pm

Next

Return to How To...

Who is online

Users browsing this forum: No registered users and 1 guest