I’m taking a break from posting iPhone development code this week. At work I was implementing a cascading drop down list and ran into a few issues. You figure you could watch the tutorials on asp.net’s website and everything would work. Wrong! I am using the dropdownlist control in a form view on the aspx page with binding, so anytime you would submit the form it would spit out an “Invalid postback or callback argument” error. Some suggestions posted on various web pages, blogs, and message boards say to disable EventValidation on the page. What? This is WRONG, WRONG, WRONG! This will bypass all the security was built in to protect against injection attacks. As one of my college professors would always say: “bad dog!”

What you really want to do is register all of the possible values for each dropdownlist. Where can you do this? You have to overriding the Render sub procedure in the code behind file. Here is sample code to fix this issue:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
Protected Overrides Sub Render(ByVal writer As System.Web.UI.HtmlTextWriter)
        If (Me.FormView1.CurrentMode = DetailsViewMode.Insert) Then
            Dim ddl1 As DropDownList = CType(Me.FormView1.FindControl("ddlDepartment"), DropDownList)
            Dim ddl2 As DropDownList = CType(Me.FormView1.FindControl("ddlEquipment"), DropDownList)
 
            'Load the data from the Departments table into the dropdownlist control for validation
            Dim departmentsAdapter As New DepartmentsTableAdapter
            For Each row As DataRow In departmentsAdapter.GetDepartments
                Page.ClientScript.RegisterForEventValidation(ddl1.UniqueID, _
                Trim(row("DepartmentName").ToString()))
            Next
 
            'Load the data from the Equipment table into the dropdownlist control for validation
            Dim equipmentAdapter As New EquipmentTableAdapter
            For Each row As DataRow In equipmentAdapter.GetAllEquipment
                Page.ClientScript.RegisterForEventValidation(ddl2.UniqueID, _
                Trim(row("EquipmentName").ToString()))
            Next
        End If
 
        MyBase.Render(writer)
 
End Sub

I also needed to add required field validators to the drop down lists. This will make sure the user actually selects a value. To do this was pretty simple, you just need to set the InitialValue equal to “”. See the sample code below:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
<cc1:CascadingDropDown  ID="CascadingDropDown1" 
                        runat="server" 
                        Category="Department"
                        LoadingText="Loading..." 
                        PromptText="Select a Department"
                        TargetControlID="ddlDepartment" 
                        ServiceMethod="GetDepartments" 
                        ServicePath="EquipmentService.asmx">
</cc1:CascadingDropDown>
<cc1:CascadingDropDown  ID="CascadingDropDown2" 
                        runat="server" 
                        Category="Equipment"
                        LoadingText="Loading..." 
                        PromptText="Select Equipment"
                        ParentControlID="ddlDepartment" 
                        TargetControlID="ddlEquipment" 
                        ServiceMethod="GetEquipment" 
                        ServicePath="EquipmentService.asmx">
</cc1:CascadingDropDown> 
 
 
 
<asp:DropDownList ID="ddlDepartment" runat="server" 
			      SelectedValue='<%# Bind("Department") %>'>
</asp:DropDownList>
 
<asp:RequiredFieldValidator id="RequiredFieldValidator1" runat="server" 
				    ControlToValidate="ddlDepartment"
            			    InitialValue=""  ErrorMessage="Department is required" 
				    Display="Dynamic" >*</asp:RequiredFieldValidator>
 
<asp:DropDownList ID="ddlEquipment" runat="server" SelectedValue='<%# Bind("Equipment") %>'>
 
</asp:DropDownList>
<asp:RequiredFieldValidator id="RequiredFieldValidator2" runat="server" 
				    ControlToValidate="ddlEquipment"
        			    InitialValue=""  ErrorMessage="Department is required" 
				    Display="Dynamic" >*</asp:RequiredFieldValidator>

That’s it! You now have cascading drop down lists that are fully functioning in a data bound formview.



**This tutorial is out of date, look for a new one to come very soon**

I figured I would put together a simple tutorial since I’ve been getting a lot of traffic based on “iPhone Human Interface Guidelines.” This is probably due to one of my earlier blog post, “Developing My First iPhone App.” I failed to adhere to the guidelines in the beginning, so my app was originally rejected. Here is a simple tutorial so you don’t have the same issue as I did.

 

Download the Reachability project from Apple. The link to the project is:
http://developer.apple.com/iphone/library/samplecode/Reachability/index.html

 

The two files we will need are: Reachability.h and Reachability.m

 

Add SystemConiguration Framework:
1. Control click (right click) on the Frameworks folder and select Add then select Existing Frameworks.
2. Scroll down and select SystemConfiguration.framework.
3. Click Add.
4. Control click (right click) on the project icon and select Add then select Existing Files.
5. Find the Classes folder in the Reachability project, and select the files Reachability.h and Reachability.m.
6. Click Add, then make sure the check box is selected for “Copy items into destination group’s folder (if needed).”
7. Click Add.

 

Inside ViewController.h file, add the following statement to the top of the header file.

1
#import "Reachability.h"

 

Inside the interface definition of the view controller, add the variable definitions:

1
2
3
4
5
NSString *urlAddress;
NSURL *url;
NSURLRequest *requestObj;
NetworkStatus remoteHostStatus;
NetworkStatus internetConnectionStatus;

 

Add the following properties:

1
2
3
4
5
@property (nonatomic, retain) NSString *urlAddress;
@property (nonatomic, retain) NSURL *url;
@property (nonatomic, retain) NSURLRequest *requestObj;
@property NetworkStatus remoteHostStatus;
@property NetworkStatus internetConnectionStatus;

 

Inside ViewController.m file add the synthesize statements after the implementation statement:

1
2
@synthesize webView, urlAddress, url, requestObj;
@synthesize remoteHostStatus, internetConnectionStatus;

 

Inside the viewDidLoad method, add the following lines of code to set the variables:

1
2
[[Reachability sharedReachability] setAddress:@"http://www.apple.com"];
[[Reachability sharedReachability] setNetworkStatusNotificationsEnabled:YES];

 

Inside the programming logic, use the following lines of code to test network connectivity. Substitute the code you would like to execute where the “NSLog(@”Connection Made”)” statement is.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
// Query the SystemConfiguration framework for the state of the device's network connections.	
self.remoteHostStatus = [[Reachability sharedReachability] remoteHostStatus];
self.internetConnectionStatus = [[Reachability sharedReachability] internetConnectionStatus];
 
// Check if there is a connection
if (self.internetConnectionStatus == NotReachable && self.remoteHostStatus == NotReachable) 
{
     UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Error Loading" 
                                     message:@"No Internet   Connection" 
                                     delegate:self cancelButtonTitle:@"OK" otherButtonTitles:nil]; 
     [alert show]; 
     [alert release]; 
} else {
        NSLog(@"Connection Made");
}

 

Don’t forget to clean up and add the following statements to the dealloc method.

1
2
3
[urlAddress release];
[url release];
[requestObj release];


Step 1: Download Cocos2d from the project website.

Step 2: Unzip the downloaded file in Step 1. If you are running Snow Leopard, it most likely will be in the downloads folder. Move the newly unzipped folder to the Desktop.

Step 3: Open Terminal and change the directory to the cocos2d folder on the desktop.

1
cd desktop/cocos2d-iphone-0.8.2

Step 4: Run the install template script.

1
./install_template.sh

The process is complete. Startup XCode and have fun!



PA Traffic Cams iPhone iPod Touch App
Apple’s iTunes is a little lacking in the department of rating apps. Mostly when anyone rates an app they do so when they are deleting it from their iPhone, or if they really really love the app. Another thing that is lacking is allowing the developers to have a line of communication with the app users. I thought a survey might help bridge this gap and help me to communicate with the users of my app. I’ve had a survey online since July to collect some feedback from the users of my app.

Results:

Out of 62 people who have filled out the survey, PA Traffic Cams has an overall rating of 3.9 out of 5. Mostly everyone said they would recommend the app or already has recommended it. There were 4 people who said they wouldn’t.

Features:

Over half of the responders have said they loved the traffic speed map feature, and almost all of the rest have found it moderately to somewhat useful. I’m glad that it was a useful feature. Google has released a newer version of their maps. I’m waiting on them to implement this feature into the latest version of their maps. Since I am running the older version, it runs a little bit on the slow side.

One thing to note, I do not control how many cameras or in which location the cameras are placed. PennDOT is solely responsible for the cameras, and I am in no way shape or form associated with them. I merely have created an app to allow users to easily navigate and view them. I try my best to check PennDOT’s website and update the app with new cameras when they are made available. If you know a link to any cameras not on the app, please send me an email and I will work on adding them.

A few of you have requested making this app for the BlackBerry. I’m sure people on the Android will also want this app. I unfortunately do not own a BlackBerry or an Android which creates a little bit of a challenge for me. I can test the app in the simulators, but I have no way to know if it will actually work on the device. I don’t ever want to put out software that does not function. Things may change in the future, but for the moment I will not be developing for the other phones.

Thank You!

Thank you to everyone who has filled out the survey. I do appreciate the time everyone took to fill it out. Your feedback will allow me to determine what features to add in upcoming releases. Speaking of which… If you have an idea please send me an email, I would love to hear about it.



For over the past year and a half, I’ve been working full-time and then taking classes on Saturdays. I would have three classes with a 30 minute lunch between the second and third classes. While this has been very challenging, it also has been just as rewarding. Taking the business classes has helped me to grow as a better developer.

What’s next?

I finished the MBA up this past Sunday, and now I have some free time again.
So, I will be working on some iPhone development in my free time. I plan on writing about it and providing some things I find useful and would like to share. I also plan on putting out some coding examples as well as doing a Cocos2d presentation for Cocoaheads Pittsburgh. Stay tuned in and may you have a happy holiday season!



DC Traffic Cams iPhone/iPod Touch app is now available in iTunes. Conveniently view Washington DC’s District Department of Transportation traffic camera images at the touch of a finger. Most of the major Washington DC area roadways are included in this application. Other features include a map of traffic speeds, and a traffic feed of accidents, construction, and road closings. Check it out!



Quacktastic Lite iPhone/iPod Touch app is now available in iTunes.  This is the free version of Quacktastic which contains ads.  Check it out!



I have upgraded WordPress to the latest version. I am working on integrating it into the look and feel of the rest of the website.  There are a few features that the newer version offers.  One of them is the ability to publish blog posts through WordPress’s iPhone app and iPhone based themes for view on the iPhone.  Please check back soon.



PA Traffic Cams iPhone AppI was brainstorming about continuous improvement for my iPhone/iPod Touch apps. I think the information I’m learning in my MBA classes is helping steer my thought process lately, which is totally a good thing. Anyhow, I noticed that users were not being presented with a good image in iTunes of what PA Traffic Cams actually does. So I replaced the primary screenshot with the camera view image. Now users are presented with a screenshot of a camera showing traffic. I think this change should provide a better experience for the user.

It is probably a small ratio of people who take the time to click the next arrow, or fully read the entire description. Having the “wrong” image as the primary screenshot has probably deterred people from downloading my app. This one change has produced a significant improvement!

In other news, I also created a short survey of questions on PA Traffic Cams. Please help me out and answer the questions, so that I can provide the best possible app that I can. The survey is available on the PA Traffic Cams website.



PA Traffic Cams iPhone iPod Touch AppPA Traffic Cams version 1.1 is now available in the iTunes App Store. New features in this version included a interface enhancements and traffic maps with speeds for Pittsburgh, Philadelphia, and Allentown. This version also fixes some cameras in Harrisburg, Scranton/Dunmore, and Allentown.

PA Traffic Cams Website

Don”t forget to check out my other iPhone/iPod Touch app. Quacktastic is a quacking blue duck that is sure to entertain kids as well as adults.