Home > 2010 Fall DPS913 > DPS913 APD601 Lab 4 (due Mon Nov 8)

DPS913 APD601 Lab 4 (due Mon Nov 8)

November 1, 2010 Leave a comment Go to comments

Lab 4 enables you to create a simple navigation-based app that uses a Core Data store. It is due on Monday, November 8.


DPS913 APD601 Lab 4 – due Mon Nov 8

Assigned: During Week 7

Due date: Monday, November 8, 2010, at 11:40am

Grade value: 3% of your final course grade

Grading method: The following will be checked:

  • Completeness and adherence to iOS app coding principles
  • Correct interactive operation of the app’s logic
  • Correct use of a Core Data store


Before you begin

Configure your Xcode environment as described in the “Before you begin” section of Lab 1. This will ensure that your work can be uploaded for grading.



Work with a navigation-based application.

Design and develop a simple Core Data model.

Create and view objects that are persisted in a Core Data store.


Concepts that you will learn

  • Navigation-based app style
  • Data persistence with Core Data
  • More about table view cell configuration


Introduction to the problem that you will solve

An app is needed that will enable the user to view a list of “tasks”, and also to quickly add or edit a task item.

The following screens show the startup view, a list of tasks, and details for a task. Tapping one of the items on the list will show the details for the item:

The following screens show the “add task” functionality. The first screen shows the view controller that gets pushed when the user taps the + (plus) button on the startup view/list. The second screen shows how the view scrolls up when the user needs to edit the UITextView.



Create a new iOS app, from the “Navigation-based Application” template, using Core Data. Name it “Tasks”.

Create the Core Data model. The entity will be named “Task”. It will have the following attributes:

  • taskTitle – String
  • taskDetails – String
  • priority – Int 32
  • completed – Bool
  • created – Date


You need only two view controllers in your app. The root view controller is a UITableViewController subclass, and it is provided by the project template. The other view controller can be a standard UIViewController subclass, which will support “display” and “edit” functionality.

The table view cell configuration must include the following:

  • An image that shows the task’s “priority”
  • A text label that shows the task’s “taskTitle”
  • A disclosure accessory


A task’s priority can be 1 (high), 2 (medium), or 3 (low). No other numbers are possible – you may want to have Core Data enforce that.

The images for the task priorities, and for a “completed” check mark image, can be downloaded from the example app download area. Look for a file that includes “Lab 4 Images” in its name.

The standard UIViewController subclass that displays a task’s detail must have the following user interface objects:

  • UISegmentedControl – for the task priority
  • UITextField – for the task title
  • UITextView – for the task details (its height should be 180 pixels)
  • UILabel – for the date created date/time stamp
  • UISwitch – for showing that a task’s completion status


Navigation bar buttons

The root table view controller is already configured with “Edit” and “+” buttons. You will have to modify the implementation to support your needs.

The detail view controller, in “task display” mode, will simply show a left-side navigation/back button, which is the expected default. When the UITextView is being edited, a right-side “Done” button will appear, to support the user’s intention to end editing.

The detail view controller, in “task add” mode, will show a left-side “Cancel” button, and a right-side “Save” button. As with the other mode, when the UITextView is being edited, a right-side “Done” button will appear, to support the user’s intention to end editing. Incidentally, while in “task add” mode, programmatically disable the UISwitch.


Lab 4 guidance

There are a number of issues that you will encounter as you work on Lab 4. Many of them are discussed below.


Modifying your Core Data model after running your app in the iPhone Simulator

Remember – if you change your data model, delete the app from the iPhone Simulator, before you build-and-run again.


Why only one additional standard view controller?

You need only one additional standard UIViewController subclass. For an existing task, it will display its details, and allow it to be edited.

How are editing changes persisted? We suggest implementing the viewWillDisappear: method.

For a new task, the view will appear, with buttons for “Cancel” and “Save”.

Therefore, in summary, this view will appear as a result of either of these actions:

  1. The + button is tapped
  2. A table view row/item is tapped


Fetched results controller configuration

Remember to clear the cache just before creating the fetched results controller.

Configure the sort descriptors so that you display the tasks in priority order (1 at the top), then by task title (alphabetic, ascending).


Displaying the startup table view controller

As stated in the specifications, each table view cell will include an image.

If the task is “completed”, show the green-coloured check mark. Otherwise, show the image that matches the task’s priority. Notice that the image names are formatted, and include a digit that will match the task priority. Take advantage of that fact as you configure the cell.

Obviously, this view will need a title.

You may need to implement viewWillAppear: to re-load the table view data.


Creating a new task

You will have to decide how you can tell whether a managed object is “new”, or is one for an existing task.

This information is needed, so that you will be able to display the right data in the user interface objects.


Core Data attribute types

Core Data has a “Bool” type. It is actually an NSNumber (that wraps an integer):

  • 0 (zero) means NO
  • 1 (one) means YES


Therefore, when you want to store a BOOL in a Core Data Bool attribute, you will have to use this:

[NSNumber numberWithBool:YES]

When you want to read a BOOL from a Core Data Bool attribute, you will have to use its boolValue.


Keyboard handling with a UITextView

In the past, you learned how to handle the keyboard when working with a text field.

With a UITextView, things are a little different. Why? A UITextView is intended as a scrollable, multi-line text entry (and display) area. The user is also able to tap “Return” to enter a new line. Doing so will not signal the end of an editing operation, like it could with a text field. Therefore, as a best practice when working with a UITextView, give the user a way (e.g. a button) to signal that they’re done editing.

The view controller must still implement keyboard handling delegate methods. First, make it conform to the UITextViewDelegate protocol. Then, implement two methods:

  • textViewDidBeginEditing:
  • textViewDidEndEditing:


The textViewDidBeginEditing method will do two (2) things:

  1. Replace the right-side navigation bar button with a “Done” button, so the user can signal that they’re done editing
  2. Shift the view up so that the UITextView appears nicely


Before replacing the original right-side navigation bar button, we suggest that you save it, perhaps in a view controller property. That way, you have easy access to it, and can restore it quickly. Alternatively, you could just re-create it when you need to.

The textViewDidEndEditing method wil do three (3) things:

  1. Restore the original right-side navigation bar button
  2. Dismiss the keyboard
  3. Shift the view back down to its original location


So, the big question is this: How does your “Done” button signal the end of an editing operation?

Well, you know that a navigation bar button must specify a target:, and send a message to it (its action: argument). Therefore, send the endEditing: message to the UITextView. Then, the UITextView, running in the Cocoa runtime event loop, will call the textViewDidEndEditing: method. (Don’t call the textViewDidEndEditing: method directly yourself. Use the built-in auto-magic messaging concept.)


Send me your work

Make sure that you have configured your Xcode environment to avoid sending the intermediate build files. This will ensure that your uploads to me are the right size.

Follow these instructions to send me your work:

  1. Make sure your project works correctly
  2. Locate your Tasks project folder in Finder
  3. Right-click the folder, and choose Compress “Tasks”, which creates a zip file
  4. Visit this page: http://matrix.senecac.on.ca/~peter.mcintyre/dps913/, and upload Tasks

Categories: 2010 Fall DPS913
  1. Derek Lo
    November 4, 2010 at 4:53 pm

    When viewing the details of a task, is the user allowed to change any of the details? Since there is only a Back button but no save button.

    • petermcintyre
      November 5, 2010 at 6:53 am

      Yes, the user can make changes. In the section “Why only one additional standard view controller?”, it suggests that you implement the viewWillDisappear: method to save your changes.

  1. No trackbacks yet.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

%d bloggers like this: