iOS - The Home Screen (Without Good Design)

Many mobile apps have a home screen which is displayed each time the app is launched. Based on the requirements I've (previously) put together for my app, I've determined that Futile Fishing will have a home screen.

Based on my design, I can envision four key functions available on the screen:

  1. Plan a future fishing trip
  2. Log a completed fishing trip
  3. Immediately capture the results of a catch, perhaps with the camera
  4. Locate and record potential fishing spots

As in prior sections, a home screen is simply another view controller that happens to be the default view. So, I'll create a class named HomeViewController which subclasses UIViewController.

The interface file is as follows:

  1. #import <UIKit/UIKit.h>
  2. #import "EventNotifier.h"
  4. @interface HomeViewController : UIViewController <EventNotifier>
  6. -(IBAction)buttonClicked:(id)sender;
  8. @end

The code implements the EventNotifier protocol, and it has a single method for handling the clicking of a button.

Next, I'll update EventManager.h to support navigation events for all four buttons. The updated file:

  1. #import <Foundation/Foundation.h>
  3. #define EM_USER_LOGOUT 100
  4. #define EM_USER_LOGIN 101
  5. #define EM_REQUEST_LOGOUT 102
  7. #define EM_NAV_PLAN_TRIP 103
  8. #define EM_NAV_LOG_TRIP 104
  9. #define EM_NAV_CAPTURE_CATCH 105
  10. #define EM_NAV_LOCAL_SPOTS_MAP 106
  12. @protocol EventManager <NSObject>
  14. -(void) handleEvent: (int) eventID withData: (id) data;
  16. @end

I'll now move on to the .xib file and add four buttons to the screen. I'll also link each button to the buttonClicked: method. However, since all four buttons are attached to the same method, I'll need a way for figuring out which button has been clicked. The answer is to use a property named the 'tag'. This can be updated in Interface Builder, and I'll set the value to be equal to the navigation event value I previously defined. So for example, the tag for the "Plan a Trip" button will be 103.

The implementation of HomeViewController is as follows:

  1. #import "HomeViewController.h"
  4. @implementation HomeViewController {
  5. id<EventManager> eventManager;
  6. }
  8. - (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil {
  9. return [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
  10. }
  12. -(void) setEventManager: (id <EventManager>)_eventManager {
  13. eventManager = _eventManager;
  14. }
  16. -(IBAction)buttonClicked:(id)sender {
  17. [eventManager handleEvent:((UIButton *)sender).tag withData:nil];
  18. }
  20. @end

This implementation is very basic: Whenever a button is clicked, the tag is fired as an event to the eventManager. And since the existing eventManager gracefully ignores unknown messages, there's no need to update the logic. The only remaining step is to instantiate a HomeViewController instance and make it the default view. After doing this and launching the app, the following is displayed:

Even though the code "works", it's an incredibly poor first impression of the app. Chances are that a new user will immediately uninstall the app and move on to the next choice they have. I'm going to revise the UI, but I'll first build a rudimentary Android version to match this iOS version.