I’ve made significant progress on my prototype iPhone app since my last post. I’m continuing to learn something new during each coding session. This post contains my learning nuggets and a few code snippets that I hope you’ll find useful.
Table View Development
- Set a table cell’s text elements from your model in thecellForRowAtIndexPath method
- Set a cell’s row height by implementing the heightForRowAtIndexPath method
- Change the appearance of a cell’s label text (textLabel and detailedTextLabel) by setting the corresponding property.
- Respond to row selections in the didSelectRowAtIndexPath method. The code for inclusive and exclusive selection is in Apple’s iPhone Table View Programming guide
Displaying dates requires the use of the NSDateFormatter class.
- Avoid learning the hard way, case matters in your date format strings, e.g., yyyy-MM-dd. Here’s a good post that covers the problem.
- Computing dates (or what Apple refers to as calendrical calculations) is a bit too verbose from me. Here’s how to calculate the top of the hour.
For applications accessing internet resources, here’s a few tidbits:
- To indicate network activity, it’s easy to add spinner or UIActivityIndicatorView to a view. However, if the main thread is too busy, it will not appear.
- The result of a URL connection (or NSURLConnection) is a binary NSData object, convert it to a string by invoking initWithData in NSString.
- Parsing JSON objects is a breeze with the JSON Framework for Objective-C. By the way, for server-side Java, check out Flexjson, works like a charm.
Is parsing newlines as simple as searching for “\n”? No, take a gander at this code from Apple’s documentation:
Lastly, Google search and stackoverflow are your friends. If you get stuck, Google it, you’ll most likely find the answer in stackoverflow or the iPhone Dev SDK forum. (However, always read Apple’s iPhone programming guides first).
Well,that’s all I have for now, happy programming!