Archives

My First iPhone App, One Step at a Time – Part 1

I’ve recently started trying to learn how to create iPhone apps and 20 or so tutorials later I’m no better off then when I started. I could follow someone else’s instructions step by step but when I got to the end I had no idea what I had just done or how to reproduce it. So I decided to stop the tutorials and start my own app and just do one thing at a time and maybe this will help me learn in baby steps. I’m going to try and write it all down here for my documentation but maybe it might help someone else as well. So, here we go.

Part 1

Goal for this step: Read from a database and display the data in a UITableView

Let’s create a new project in Xcode and create a new Single View Application.

 

 

Once the project is created, click on the MainStoryboard.storyboard and delete the view controller created by the project. Then drag a new Table View Controller onto the storyboard.

 

Now go into the ViewController.h and change the ViewController to inherit from UITAbleViewController instead of UIViewController.

@interface ViewController : UITableViewController

Now go back to the storyboard and click on the view controller, then click on the Identity Inspector tab and make sure the class is set to ViewController.

 

Save the project and run. You should see an empty TableView.

 

Now its time to create the database. Download SQLite Manager for FireFox and create a very simple table. For now all the column are going to be text just to keep things simple.

 

Drag the database mySchedule.sqlite and drop it on Xcode. Be sure to select “copy” items into destination group’s folder.

 

 

Create a class for the database by clicking “file” on the menu and then “new” then “file”. Select the “Objective-C class” and select “next”.

 

Change MySchedule.h to look like below. Defining the pointers and properties of the table columns.

 @interface MySchedule : NSObject{ NSString *weekof; NSString *monday; NSString *tuesday; NSString *wednesday; NSString *thursday; NSString *friday; NSString *saturday; NSString *sunday; } @property(nonatomic, copy) NSString *weekof; @property(nonatomic, copy) NSString *monday; @property(nonatomic, copy) NSString *tuesday; @property(nonatomic, copy) NSString *wednesday; @property(nonatomic, copy) NSString *thursday; @property(nonatomic, copy) NSString *friday; @property(nonatomic, copy) NSString *saturday; @property(nonatomic, copy) NSString *sunday; @end 

Add “import sqlite3.h” to both ViewController.h and ViewController.m.

Create an NSMutableArray called scheduleArray to hold the data we will read from the database.

Create a method called scheduleList.

ViewController.h should look like this.

 

 

 

Set the identifier in the proptype cell to ScheduleCell so we can refer to it by name in our code

 

Now set the text of the table cells initial view in cellForRowAtIndexPath

Compile and Run and we have an app that displays dates from a database in a tableView.

Download the project files for Part 1 – MySchedule Part 1

about tgray

For 19 years I have been perfecting my craft to create the best designs for your needs. My designs are a tasteful blend of art and functionality that come together to make a successful web site.

In 1989 I began my career in art and design after graduating from the University of Arkansas with the opening of a custom sign business. My career path slowly migrated into the computer design field and after a couple years the design path gave way to a career in computer programming. I spent about ten years working in small shops, international organizations and global companies in the computer programming arena all the while keeping my love for art and design alive on the side. As the internet began to become more widespread, I began to see where I could weld my love for design and computer programming into one. Web design, the perfect medium.

If you would like to find out more, please contact me or join me on LinkedIn.

about tgray

For 19 years I have been perfecting my craft to create the best designs for your needs. My designs are a tasteful blend of art and functionality that come together to make a successful web site.

In 1989 I began my career in art and design after graduating from the University of Arkansas with the opening of a custom sign business. My career path slowly migrated into the computer design field and after a couple years the design path gave way to a career in computer programming. I spent about ten years working in small shops, international organizations and global companies in the computer programming arena all the while keeping my love for art learn more…

Vegan Chili

Prep Time: 30 mins | Cook Time: 1 hr 45 mins | Servings: 8 to 10 servings | Difficulty: Medium

Ingredients:

  • 1 lb. cooked pinto beans
  • 12 ounce bag Boca Meatless Ground
  • 2 tbsp Earth Balance Buttery Spread
  • 1 large onions, chopped
  • 1 tbsp chopped garlic
  • 2 3/4 tbsp oregano
  • 1 1/2 tbsp ground cumin
  • 6 ounce can tomato paste
  • 1 cans tomatoes, in blender
  • 1/2 tbsp salt
  • 1/2 tbsp black pepper
  • 4 tbsp chili powder
  • 1 tbsp sugar

Directions:

Cook onions and garlic in buttery spread until onions are clear. Then put in pinto beans and veggie crumbles. Put in other seasonings and tomatoes and cook slowly after bringing to a boil. Cook about 1 1/2 or 2 hours. Add enough water so it won’t stick. Slow simmer with lid on.