Monday, 18 November 2013

KAL Calendar - how to use

Source code:
storyboard version
xib version

In this article, I like to add a few more explanation to the following article.
http://www.edumobile.org/iphone/iphone-programming-tutorials/custom-calender-view-in-iphone/

The above link is a great article, but it was missing a few critical points and some screen shots.
The above link will  be referred as 'Edu URL' for the rest.
My environment is XCode 5.1 but using the Simulator IPhone->iOS6.1


Firstly download the KAL source code.
https://github.com/klazuka/Kal

Drag and drop whole src folder from Finder  into your Xcode project.


Build and run. I chose iOS6.1 as simulator.
(when iOS 6 SDK doesn't show:





We need to implement protocol in src/KalViewController.h
I think the Edu URL is incorrect about this one. It's not your viewcontroller. Protocol should be implemented from KalViewController.h.







Open your controller, ViewController.h.
As Edu url, declare three properties.
Note that, in the source code below, you imported "KalViewController.h" to use <calendarDelegate>



Open story board. As Edu URL, make one button and two labels.
Connect each control.

Build and run. You must have ARC error.
Find 'auto' in Build setting and disable ARC check.





Build and run. Your button should be working and returning error (we didn't implement function yet)
Go to ViewController.m. Implement date().


Build and run. At this stage, it doesn't make compile error but it doesn't show KAL view either.
It's because we haven't done NavigationControl. 

Open Main.storyboard.
Add NavigationControl.
The video without sound may help how to add NavigationControl in story board.

So, now, when you click 'Get Date' button, it opens calendar view.



Then we want to dismiss the calenar view when you select the date.
Open ViewController.m and implement delegate function dateSelectedAs().

Now when you click a date, it calls
KalViewController.m -> didSelectDate()
then it calls delegate function,
ViewController.m -> (void) dateSelectedAs()
and it dismisses the Calendarview.


Note that KalViewController.m didSelectDate() is called whenever the calendar view is called. NSLog shows that the function is called when the first date is showing and today's date is showing. 

So, in KalViewController.m, I added int variable, calCount. This int was used to call delegate function only when use clicks the date from calendar view. (1st and 2nd call of the function ignored).



Build and run. You will see the screen shots below.










Thursday, 17 October 2013

Change dataset to xml

Before we improve our web service, we practice our little xml conversion from dataset.
http://msdn.microsoft.com/en-us/library/58a18dwa.aspx


It's an web application. It doesn't have to be.

It prints out Hello There. but what it really does is making an xml file.



 We call a stored procedure. And change it to dataset ds. And the dataset is changed to XML string. Then it is written to a file.


 Result file looks like this.
 Note that null value doesn't make XML attribute, but when there is data, the attribute is created.


Now we develop this program a bit more.
(1) We want to save XML result to a string. (http://stackoverflow.com/questions/8384014/convert-dataset-to-xml)
(2) Then we want to select the first element from the XML string.
 Result looks like this.



Thursday, 26 September 2013

How to create / use web service

For an overview, we create a webservice project and a website calling that web service.
Web service project looks like below and is under localhost

Web site looks like as below and is under c:\work.



Firstly, I followed the link below showing nicely how to create web service and use it.
http://msdn.microsoft.com/en-us/library/8wbhsy70(v=vs.90).aspx

I started following the link above and created a web service web application. My localhost inetmgr looks like below. I haven't changed any Advanced settings in IIS but just uploaded the capture here for future reference.





The web service is a small program changing F temperature to C.



If you mess up Application Pool you can get this error:

Otherwise, you can see the working page as below:

Then I launched the webservice to live server. This just meant copying whole folder from localhost to the server folder.

Once I change to live server from localhost, I got the below error:
It was because my folder on webserver was not set up as web application.

After changing it to Application, the web service URL starts working.
 But the F to C change function says, it only works in localhost.
 After searching on Google, i found that it's not error, but for security.

Web service is now working. Next step is to use it.
Create another website and call it. I couldn't find web reference, so i clicked 'Add Service Reference'.
 Put the live URL and name web service.
 In Default.aspx, put some controls.
 On source code behind, when you type in 'temp...' it automatically recognzie the webservice name TemperatureConvert. Good!

Note the code part how to use the webservice and its function. It's slightly different from what you can find from Google. I don't know. It worked that way in my case.

The program works fine.
 It looks exactly same as the MSDN website.

That's it for this blog.

Next step will be passing XML through web service:
http://msdn.microsoft.com/en-us/library/58a18dwa.aspx

Thursday, 8 August 2013

Phonegap drag and drop image

I thought it was easy.
I thought if I copy and paste of HTML5 Drag and Drop source from
http://www.w3schools.com/html/html5_draganddrop.asp into the index.html, it would work.

I was wrong.

Touch phone doesn't recognize mouse event.

After all the search, I found a working example.
http://popdevelop.com/2010/08/touching-the-web/

If you check the URL http://sewa.se/drag/ in the Android emulater browser, it works!!
View source-> copy and paste into your index.html.

Or download the index.html below.
https://docs.google.com/file/d/0B_V2TTxMUlvVQVJNMlNORGl1WGs/edit?usp=sharing

Then I did little bit more to drag and drop image one another.


You can get the updated index.html below.
https://docs.google.com/file/d/0B_V2TTxMUlvVWmx5Smp2N21vZlE/edit?usp=sharing