Skip to main content

iOS Tutorial Resources and UITableViewController

I began my app with a super simple view for the user's history. I used 1 huge label and just threw text at it. It didn't look pretty, but it got the data on to the screen. As I have been working with the app on a daily basis, it has become obvious to me that this is the biggest issue that needs to get addressed for the app to look more professional. Replacing this current view with something else will allow me to learn about the UITableViewController in iOS.

As with everything I have learned so far, I seem to immediately expect iOS to have a similar control and functionality to .NET. I think that has probably done me a disservice by assuming something new will be similar to something I already know. Most of what I have learned to this point share aspects of what I know, but are almost never exact matches. UITableView I expected would likely work like either a listview or a repeater, and it has some similarities, but it also has some quirks that I find odd. At least based on the tutorials I looked at, you don't just bind a collection to the View and then know that you will have 1 record of that data for each row. Instead they have you define the number of rows to show and how many sections you will have. These values could be, and in the demos are, just hard coded numbers that don't need any relation to the data you are showing. I guess by only looking at counts could be more efficient than entire collection, but given that once you start using real data you are going to be using the count of that collection anyways I don't see why it doesn't just use the data.

Moving on. The view now knows how many sections and how many rows to display. It has a method that is similar to the .NET repeater's ItemDataBound method. It gets called for each row, and gives you the index of the row you are currently on. Typically then you would grab the item from your collection at the same index and display its data. Again, this seems like something that probably ought to just be handled for you.

I wonder if there are better techniques for the issues and I just have been finding articles and tutorials that assume the reader has no previous programming experience, or if .NET just handles things that much differently.

Reading through some tutorials have shown really poor ways to accomplish things in iOS, however I haven't found out that they were poor tutorials until after I get fed up and look for a better way. For example, one walkthrough for using the UITableView describes the "simple" approach for showing data in each cell. First you add a label to the cell. Then you add a tag, a numeric value, to the label so that you can find that label, by its rage, in the code loop for data binding. Really? So up to this point, I have been able to name controls and then refer to them in code by that name, now I have to give each control a number that will be used to find it?

Researching further I find another approach, which is at least to me much simpler and much more likely to be used with real data. You can use a subclass, and cast your cell to that subclass rather than trying to grab each control by the tag. Then within that subclass you can have properties that are your labels and other controls, which you can interact with by name. I understand wanting to make your demo as simple as possible, but just adding a subclass with named controls seems much easier than needing to make sure your tag number always match up.

Pushing forward I was able to get the UITableViewController working and displaying my data in a much nicer, more professional looking format. Perhaps I am expecting more out of the resources that I have used than I should be, or perhaps I have simply found some really poor examples and didn't know enough to realize that I should have moved on to other places. Either way I am progressing with my app, and learning more and more about iOS development as I go.


Popular posts from this blog

Converting a Large AngularJS Application to TypeScript Part 1

I work on a project that uses AngularJS heavily. Recently we wondered if using a preprocesser like CoffeeScript or TypeScript for our JavaScript would be beneficial. If our team is going to switch languages, we would need to be able to convert existing code over without much pain and we would have to find enough value in switching that it would be worth the conversion.

I had read an article that stated that because TypeScript is a SuperSet of JavaScript, you could convert a plain JavaScript file to TypeScript by changing the extension to .ts and not much else would need to change. I wanted to test out this claim, so I took a file that I was familiar with, an Angular Controller, and tried to convert it to TypeScript to see how much effort it would take and then try to figure out where we would benefit from using TypeScript.

This is what the controller JavaScript file looked like to start out with:
(function () { 'use strict'; angular .module('app') …

Converting a Large AngularJS Application to TypeScript Part 2

In part 1 I was able to take an Angular controller written in JavaScript and convert it to a TypeScript file while doing very little to change the code. In this post I am going to explore transitioning that same controller to actually use the features provided in TypeScript. This is how I left off my controller:
declare var angular: any; (function () { 'use strict'; var controller: any = function($scope){ ... } angular .module('app') .controller('controller', controller); controller.$inject = ["$scope"]; })();
While performing the translation from JavaScript to TypeScript, I would make sure at every step that the functionality I expected still worked, so if anything I did broke the system I would change it back and try again with another approach. Also if something seemed like it worked too easily, I would break it on purpose to make sure I wasn't getting a false result through browser caching a previously working fil…

Gamify TDD

I like it when things that would not normally be associated with games add concepts from games as a way to incentives you to accomplish things. Why simply go for a run if you can have an app that will track you and give you a gold star if you do better than you did the last time? Why go to the coffee shop that only gives you coffee if the other one will give you points that you can redeem for free drinks eventually?

I was recently introduced to CodeSchool, an online training system similar to PluralSight, it has video courses and challenges you can take to prove that you retained what the video taught. CodeSchool also adds badges and tracks to your learning, so as you complete a video and its challenges you get a badge. Complete a collection of courses within a specific discipline and you become a master of that discipline.

Some of these incentives are not tangible and really don't mean much in the real world, but they tend to work for me. If I start working towards a large goal a…