Showing posts with label tutorial. Show all posts
Showing posts with label tutorial. Show all posts

Sunday, December 23, 2012

Tutorial: How To Extract iPhone App Artwork Downloaded From iTunes - Example Using Path's iOS App

1. Search for the app in the iTunes store and download it.

2. Click on Apps in the left toolbar and search for the app. Then right click and select "Show in Finder".



3. Open the following web page in Apple's Safari web browser http://www.raisedtech.com/iphone-ipa-png/index.php?r=site/index. Then upload the iOS App ipa file to the website. The images stored in the ipa are compressed, and the website searches the ipa archive for all images, decompresses them, and then displays them for you. 


4. The file upload and decompression takes a while, so in the mean time create a new folder to download the extracted artwork. I'll call mine "test-artwork".

5. Download this web page image downloader script that I made using Mac Automator. It grabs the current page in Safari, retrieves all of the image urls, and then proceeds to download all of the images. 

6. Once the app is finished uploading, it refreshes the page and here you see all of the artwork for the page. 

7. Open the Mac Automator script downloaded in step 5. Leave the extracted artwork page as the front most Safari page, select the destination folder for the images, and then click run. The image downloads take a while if there are a lot of images. 

8. Complete! Once complete you should see a successful workflow and open the destination folder and there should be images that you can use for research purposes.























Tutorial: Customizing UISearchBar

 Result:

To customize UISearchBar you have to override the layout subviews method. To make it slightly more flexible I used tags to determine which background image to load. You have to define the tag in interface builder in the right side panel shown below.




//
//  KTSearchBar.h
//  CustomSearchBar
//
//  Created by Kurry L Tran on 12/23/12.
//  Copyright (c) 2012 Kurry L Tran. All rights reserved.
//

#import 

@interface KTSearchBar : UISearchBar
@property (nonatomic, strong) UIView *inputAccessoryView;
@end



//
//  KTSearchBar.m
//  CustomSearchBar
//
//  Created by Kurry L Tran on 12/23/12.
//  Copyright (c) 2012 Kurry L Tran. All rights reserved.
//

#import "KTSearchBar.h"
#import 

#define KEYBOARD_ACCESSORY_HEIGHT 62
#define kBackgroundOneTag 111
#define kBackgroundTwoTag 112
#define kBackgroundThreeTag 113
#define kBackgroundFourTag 114

@implementation KTSearchBar

- (void)awakeFromNib
{
  [[self.subviews objectAtIndex:0] removeFromSuperview];
  UIImageView *backgroundImageView = nil;
  
  self.layer.borderColor = [[self colorWithHex:0x32363c] CGColor];
  NSLog(@"Tag == %d", self.tag);
  if (self.tag == kBackgroundOneTag) {
    backgroundImageView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"searchBarBackground@2x.png"]];
    backgroundImageView.frame = CGRectMake(0.0f, 0.0f, 320, 44);
  }else if(self.tag == kBackgroundTwoTag){
    backgroundImageView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"search-bg-all@2x.png"]];
    backgroundImageView.frame = CGRectMake(0.0f, 0.0f, 320, 44);
  }else if(self.tag == kBackgroundThreeTag){
    backgroundImageView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"searchBar@2x.png"]];
    backgroundImageView.frame = CGRectMake(0.0f, 0.0f, 320, 44);
  }else if(self.tag == kBackgroundFourTag){
    backgroundImageView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"search-bg-all-dark@2x.png"]];
    backgroundImageView.frame = CGRectMake(0.0f, -1.0f, 320, 44);
  }
  
  [self addSubview:backgroundImageView];
  
}


- (void)layoutSubviews {
  
  [self setShowsCancelButton:NO animated:NO];
  UITextField *searchField;
  NSUInteger numViews = [self.subviews count];
  for(int i = 0; i < numViews; i++) {
    if([[self.subviews objectAtIndex:i] isKindOfClass:[UITextField class]]) { //conform?
      searchField = [self.subviews objectAtIndex:i];
    }
  }
  [self bringSubviewToFront:searchField];
  if(!(searchField == nil)) {
    searchField.textColor = [self colorWithHex:0x8b909c];
    searchField.font = [UIFont fontWithName:@"MyriadPro-It" size:18];
    searchField.contentVerticalAlignment = UIControlContentVerticalAlignmentCenter;
    [searchField setBorderStyle:UITextBorderStyleNone];
    [searchField setBackgroundColor:[UIColor clearColor]];
    [searchField setRightView:nil];
    [searchField setBackground:nil];

    if (self.tag != kBackgroundThreeTag) {
      UIImage *image = [UIImage imageNamed:@"MagnifyingGlassDark"];
      UIImageView *iView = [[UIImageView alloc] initWithImage:image];
      searchField.leftView.opaque = YES;
      searchField.leftView = iView;
    }else
      searchField.leftView  = nil;

  }
  [super layoutSubviews];
}

// http://stackoverflow.com/questions/1560081/how-can-i-create-a-uicolor-from-a-hex-string
- (UIColor *) colorWithHex:(int)hex {
  return [UIColor colorWithRed:((float)((hex & 0xFF0000) >> 16))/255.0
                         green:((float)((hex & 0xFF00) >> 8))/255.0
                          blue:((float)(hex & 0xFF))/255.0 alpha:1.0];
}




@end

Sample Project: http://bit.ly/VYuflp

Tutorial: Adding a Drop Shadow To Last Row of UITableView


//
//  UITableViewCell+DropShadow.h
//  TableViewCellDropShadow
//
//  Created by Kurry L Tran on 12/23/12.
//  Copyright (c) 2012 Kurry L Tran. All rights reserved.
//
 
#import <UIKit/UIKit.h>
 
@interface UITableViewCell (DropShadow)
-(void)addDropShadow;
-(void)removeDropShadow;
@end
//
//  UITableViewCell+DropShadow.m
//  TableViewCellDropShadow
//
//  Created by Kurry L Tran on 12/23/12.
//  Copyright (c) 2012 Kurry L Tran. All rights reserved.
//
 
#import "UITableViewCell+DropShadow.h"
#import <QuartzCore/QuartzCore.h>
 
@implementation UITableViewCell (DropShadow)
 
-(void)addDropShadow
{
  self.layer.shadowOffset = CGSizeMake(0, 10);
  self.layer.shadowColor = [[UIColor blackColor] CGColor];
  self.layer.shadowRadius = 3;
  self.layer.shadowOpacity = .75;
  CGRect shadowFrame = self.layer.bounds;
  CGPathRef shadowPath = [UIBezierPath bezierPathWithRect:shadowFrame].CGPath;
  self.layer.shadowPath = shadowPath;
}
 
-(void)removeDropShadow
{
  self.layer.shadowOpacity = 0;
}
@end

Example Usage: 

// Customize the appearance of table view cells.

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath

{
    static NSString *CellIdentifier = @"Cell";
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];

    if (cell == nil) {
        cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier];
       cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
    }

  NSDate *object = _objects[indexPath.row];

  cell.textLabel.text = [object description];
  NSInteger numberOfSections = [self numberOfSectionsInTableView:tableView];
  NSInteger numberOfRows = [self tableView:tableView numberOfRowsInSection:(numberOfSections-1)];

  if (indexPath.section == (numberOfSections - 1) && indexPath.row == (numberOfRows-1))
    [cell addDropShadow];
  else
   [cell removeDropShadow];

  return cell;
}

- (void)viewWillAppear:(BOOL)animated

{
  NSInteger numberOfSections = [self numberOfSectionsInTableView:self.tableView];
  NSInteger numberOfRows = [self tableView:self.tableView numberOfRowsInSection:(numberOfSections-1)];
  NSIndexPath *indexPath = [NSIndexPath indexPathForRow:(numberOfRows -1) inSection:(numberOfSections-1)];
  UITableViewCell *cell = [self.tableView cellForRowAtIndexPath:indexPath];
  [cell addDropShadow];
}










Sunday, June 17, 2012

Tutorial: Concurrency with Core Data Tutorial


I thought that all of the important Core Data articles were scattered in so many places and so I thought I should make a good set of notes. None of the text below reflect my own words, and they are taken directly from the Apple articles in the links. I had set out to start using Core Data in multiple threads, but then I realized my understanding of the theory of Core Data was weak, and so I thought I should build a solid understanding before I started programming.

Core Data Core Competencies

Core Data
You use Core Data to manage the model (in the model-view-controller sense of the word) objects in your application. Core Data is an object-graph management and persistence framework. Among other things, it:

  • Allows you to efficiently fetch model objects from a persistent store and save changes back to the store.
  • Provides an infrastructure for tracking changes to your model objects. It gives you automatic support for undo and redo, and for maintaining reciprocal relationships between objects.
  • Allows you to maintain disjoint sets of edits of your model objects. Disjoint sets are useful if you want to, for example, allow the user to make edits in one view that may be discarded without affecting data displayed in another view.
  • Allows you to keep just a subset of your model objects in memory at any given time. This is useful for keeping the memory footprint of your application as low as possible.
  • Has an infrastructure for data store versioning and migration. This infrastructure lets you easily upgrade an old version of the data file to the current version.
To support this functionality, Core Data uses a schema called a managed object model that describes the entities in your application. 


Core Data Stack

A Core Data stack is composed of the following objects: one or more managed object contexts connected to a single persistent store coordinator which is in turn connected to one or more persistent stores. A stack contains all the Core Data components you need to fetch, create, and manipulate managed objects. Minimally it contains:
  • An external persistent store that contains saved records.
  • A persistent object store that maps between records in the store and objects in your application.
  • A persistent store coordinator that aggregates all the stores.
  • A managed object model that describes the entities in the stores.
  • A managed object context that provides a scratch pad for managed objects.



Managed Object
A managed object is a model object (in the model-view-controller sense) that represents a record from a persistent store. A managed object is an instance of NSManagedObject or a subclass of NSManagedObject. A managed object is registered with a managed object context. In any given context, there is at most one instance of a managed object that corresponds to a given record in a persistent store.



A managed object has a reference to an entity description object that tells it what entity it represents. In this way,NSManagedObject can represent any entity—you don’t need a unique subclass per entity. You use a subclass if you want to implement custom behavior, for example to calculate a derived property value, or to implement validation logic.

Managed Object Context

A managed object context represents a single object space, or scratch pad, in a Core Data application. A managed object context is an instance of NSManagedObjectContext. Its primary responsibility is to manage a collection of managed objects. These managed objects represent an internally consistent view of one or more persistent stores. The context is a powerful object with a central role in the life-cycle of managed objects, with responsibilities from life-cycle management (including faulting) to validation, inverse relationship handling, and undo/redo.
From your perspective, the context is the central object in the Core Data stack. It’s the object you use to create and fetch managed objects, and to manage undo and redo operations. Within a given context, there is at most one managed object to represent any given record in a persistent store.




A context is connected to a parent object store. This is usually a persistent store coordinator, but may be another managed object context. When you fetch objects, the context asks its parent object store to return those objects that match the fetch request. Changes that you make to managed objects are not committed to the parent store until you save the context.
In some applications, you may have just a single context. In others, however, you might have more than one. You might want to maintain discrete sets of managed objects and edits to those objects; or you might want to perform a background operation using one context while allowing the user to interact with objects in another.
Persistent Store Coordinator
A persistent store coordinator associates persistent object stores and a managed object model, and presents a facade to managed object contexts such that a group of persistent stores appears as a single aggregate store. A persistent store coordinator is an instance of NSPersistentStoreCoordinator. It has a reference to a managed object model that describes the entities in the store or stores it manages.
Fetch Request
A fetch request tells a managed object context the entity of the managed objects that you want to fetch; optionally, it specifies other aspects such as constraints on the values the objects' properties must have and the order you want the objects returned in. A fetch request is an instance of NSFetchRequest. The entity it specifies is represented by an instance of NSEntityDescription; any constraints are represented by an NSPredicate object, and the ordering by an array of one or more instances of NSSortDescriptor. These are akin to the table name, WHERE clause, and ORDER BY clauses of a database SELECT statement respectively.

Persistent Store
A persistent store is a repository in which managed objects may be stored. You can think of a persistent store as a database data file where individual records each hold the last-saved values of a managed object. Core Data offers three native file types for a persistent store: binary, XML, and SQLite. You can implement your own store type if you want Core Data to interoperate with a custom file format or server. Core Data also provides an in-memory store that lasts no longer than the lifetime of a process.

Managed Object Model 
A managed object model is a set of objects that together form a blueprint describing the managed objects you use in your application. A model allows Core Data to map from records in a persistent store to managed objects that you use in your application. It is a collection of entity description objects (instances of NSEntityDescription). An entity description describes an entity (which you can think of as a table in a database) in terms of its name, the name of the class used to represent the entity in your application, and what properties (attributes and relationships) it has.

Persistent Object Store
A persistent object store maps between objects in your application and records in a persistent store. There are different classes of persistent object store for the different file types that Core Data supports. You can also implement your own if you want to support a custom file type.
Mapping Model
A Core Data mapping model describes the transformations that are required to migrate data described by a source managed object model to the schema described by a destination model. When you make a new version of a managed object model, you need to migrate persistent stores from the old schema to the new.



Summary of Concurrency Programming Guide
There needs to be a way for applications to take advantage of a variable number of computer cores. The amount of work performed by a single application also needs to be able to scale dynamically to accommodate changing system conditions. And the solution has to be simple enough so as to not increase the amount of work needed to take advantage of those cores.

The Move Away from Threads:
Instead of relying on threads, Mac OS X and iOS take an asynchronous design approach to solving the concurrency problem. In Mac OS X and iOS allows you to perform any task asynchronously without having to manage the threads yourself.

One of the technologies for starting tasks asynchronously is Grand Central Dispatch (GCD). This technology takes the thread management code you would normally write in your own applications and moves that code down to the system level. All you have to do is define the tasks you want to exectute and add them to an appropriate dispatch queue. GCD takes care of creating the needed threads and of scheduling tasks to run on those threads. Because the thread management is now part of the system, GCD provides a holistic approach to task management and execution, providing better efficiency than traditional threads.

Operation queues are Objective-C objects that act very much like dispatch queues. You define the tasks you want to execute and then add them to an operation queue, which handles the scheduling and execution of those tasks. Like GCD, operation queues handle all of the thread management for you, ensuring that tasks are executed as quickly and efficiently as possible on the system.


Dispatch queues are a C-based mechanism for executing custom tasks. A dispatch queue executes tasks either serially or concurrently but always in a first-in, first-out order.

Dispatch queues have other benefits:
● They provide a straightforward and simple programming interface.
● They offer automatic and holistic thread pool management.
● They provide the speed of tuned assembly.
● They are much more memory efficient (because thread stacks do not linger in application memory).
● They do not trap to the kernel under load.
● The asynchronous dispatching of tasks to a dispatch queue cannot deadlock the queue.
● They scale gracefully under contention.
● Serial dispatch queues offer a more efficient alternative to locks and other synchronization primitives.

The tasks you submit to a dispatch queue must be encapsulated inside either a function or a block object. Block objects are a C language feature introduced in Mac OS X v 10.6 and iOS 4.0 that are similar to function pointers conceptually, but have some addition benefits.

Dispatch sources are a C-based mechanism for processing specific types of system events asynchronously. A dispatch source encapsulates information about particular type of system event and submits a specific block object or function to a dispatch queue whenever the event occurs.

An operation queue is the Cocoa equivalent of a concurrent dispatch queue and is implemented by the NSOperationQueue class. Whereas dispatch queues always execute tasks first-in, first-out order, operation queues take other factors into account when determining the execution order of tasks.

You can use dispatch sources to monitor the following types of events:

● Timers
● Signal handlers
● Descriptor-related events
● Process-related events
● Mach port events
● Custom events that you trigger

Before you even consider redesigning your code to support concurrency, you should ask yourself whether doing so is necessary. Concurrency can improve the responsiveness of your code by ensuring that your main thread is free to respond to user events. It can even improve the efficiency of your code by leveraging more cores to do more work in the same amount of time. However, it also adds overhead and increases the overall complexity of your code, making it harder to write and debug your code. 

Tips for Improving Efficiency:

● Consider computing values directly within your task if memory usage is a factor.
● Identify serial tasks early and do what you can to make them more concurrent.
● Avoid using locks. 
● Rely on the system frameworks whenever possible.

Core Data Programming Guide

Summary of Core Data Programming Guide
1. There are several situations in which performing operating with Core Data on a background thread or thread queues beneficial, in particular if you want to ensure that your application's user interface remain responsive while Core Data is undertaking a long-running task.

The pattern recommended for concurrent programming with Core Data is thread confinement: each thread must have its own entirely private managed object context.

There are two possible ways to adopt the pattern:

1. Create a separate managed object context for each thread and share a single persistent store coordinator.

2. Create a separate managed object context and persistent store coordinator for each thread.

This approach provides for greater concurrency at the expense of greater complexity (particular if you need to communicate changes between different contexts) and increase memory usage.

Threaded Core Data
Note: You can use threads, serial operations queues, or dispatch queues for concurrency. For the sake of conciseness, this article uses "thread" throughout to refer to refer to any to these.

  • Blocks simplify function callbacks. 
  • * is a pointer to a function. i.e. int (*cmpr)(int, int)
  • ^ is a pointer to a block. i.e. int(^cmpr)(int, int)
  • A block is a chunk of executable code. The caret introduces a block literal and the curly braces enclose statements that make up the body of the block. The most common way to use a block is to pass it a method that in turn calls the block. 
  • In practice, blocks are most useful when you pass them as parameters to methods that in turn call the block. 
  • In practice, it's more convenient to use inline blocks rather than assigning the block to a typed variable and then passing it to the method.
Great Objective-C Programming Resources Here:

Programming Blocks and Uses for Blocks in C/Objective-C

Example Code:







Saturday, February 25, 2012

Tutorial: How To Uninstall Mountain Lion OS X

Story: I have a problem of downloading and installing any new Apple product once it comes out and so I downloaded and installed Mountain Lion OS X on my main machine (MacBook Air) and then I realized that it had a lot of problems and a lot of my programs were having not compatible with it, so I tried to uninstall it. I ran into a lot of trouble and there was not a lot of good info online and it took me a long time how to figure out (14+ hours), so I thought I would write a blog post so other people wouldn't have to go through the same trouble. This blog post is short because I have a ton of homework and life stuff so I just put the most essential info in it.

1. I first tried to log into my Mac Developer Account and download Mac OS X Lion through the Mac App Store, but the installer will tell you that you can't install Mac OS X Lion because you have a newer version of Mac OS X installed.


2. I then obtained the Install Mac OS X Lion through another means (you should find some way to get this). Note: You have to get Mac OS X Lion 10.7.2 or above.

Once I obtained it if you double click the installer nothing will happen. Right click the app and click show package contents.


3. Go to Contents > SharedSupport > OSinstall.mpkg and double click the package and you will get this error.



4. In Finder search for the Disk Utility App and create a partition for Mac OS X Lion.



5. Once you create a partition you have to open Terminal to change the Mac OS X version number so you can install Mac OS X Lion on the partition. 

Before:


6. To change the Mac OS X version number you have to change the settings of the file /System/Library/CoreServices/SystemVersion.plist and then modify it in a text editor. 


Before:



After:





7. Then you should be able to run the installer and install Mac OS X Lion on the disk partition. I think this worked for me. If not drag and drop the package contents of the installer app into the new partition and then restart your computer and load the new disk partition. (Restart the computer and hold the option button and then select the correct disk partition) Do not restore the Mac OS X Lion disk image into the disk partition. 

8. If you could not run the Mac OS X Lion installer from OS X Mountain Lion, mount the disk image and copy the entire contents of that into your new disk partition, and then load that on startup. 





Note: If you get errors about the disk being locked you did something wrong. Create a brand new partition and drag and drop the installer package contents into the new disk partition, and then restart the computer. 







Tuesday, October 25, 2011

iOS 5 Storyboard + UITableView Tutorial II (Improved)

Since I'm learning as well and have been reading other people's tutorials that I thought were not very good (because they either had too much clutter or did not stress the important points) I thought I would make another tutorial on the key ideas of UITableViews that I missed out on before.

Download Project: here.
1. Create a new Tabbed Application called StoryboardUITableView.



2. In the MainStoryboard file look at the attribute inspector and you will see the checkbox for Is Initial View Controller.

Common Error: Not having set an initial view controller. The simulator will popup and then just be in a deadlock and in the output log, it will say something about how your application doesn't not have a root view controller.



3. Embed a navigation controller in the first view by going to Editor > Embed In > Navigation Controller.

Note: If you delete the connection, and then control+drag from the Tab Bar Controller you will see the following in the image below. You can set the initial scene to be the first view controller by control + dragging as described before and then selecting Relationship - viewControllers. This creates a connection between the Tab Bar Controller and and Navigation Controller.




4. Suppose I create a tableview by drag and dropping it a UITableViewController, I can customize the cells in the right panel.

Key Points:

Style: Change Style of UITableViewCell
Identifier: Cell Identifier to Distinguish Prototype Cells
Accessory: The Creates The Right Facing Arrow
Size: Resize the cell by dragging it up or down.

Note: Ignore the left half of the screenshot since I made an error the first time.


5. Create a new UITableViewController called AlbumViewController and select the table view controller and change its class to AlbumViewController .




6. Suppose I created a datasource in the AppDelegate.m file and I follow the usual steps to populate the tableview. The one interesting change is here: tableview cells are now automatically allocated so the code is much simpler than before. In the AlbumViewController.m file implement the usual methods.

 (Note: Copy and paste them from the source file in the download.)


7. Change this method and you can then slide to delete a tableview cell.




8. Run and project and it will turn out like this.


Download Project: here.

http://kurrytran.blogspot.com/2013/06/fast-scrolling-customized-uitableviews.html

Wednesday, October 19, 2011

iOS 5 Storyboard and UITableViews Tutorial

In this tutorial we will:

1. Create a UITableView from scratch.
2. Learn about navigation controllers.
3. Pushing view controllers with storyboard.

Link to Download Entire Project: here

1. Create a new single view based application called "StoryboardTutorial".


2. Select the main storyboard file and then select Editor > Embed In > Navigation Controller.
Note: A navigation controller is a way to manage views. Typically you push or pop a view onto a navigation controller. You can think of this a stack.


3. Next drag and drop a UITableView from the right sidebar and place it onto the view controller.


4. Go into the ViewController.h file and add after it says UIViewController. This tells the compiler that your class will conform to the UITableViewDelegate/UITableViewDataSource protocols. A protocol is just a formal way of saying that you will implement all methods that are required so you have a functioning tableview. 




Note: The biggest benefit of declaring the ViewController.h object as such is that now Xcode will autogenerate code and most of your necessary methods you would like to implement in the tableview class. Also note, if the method is not auto-generating you're probably doing something wrong. That's the main way I know I'm doing something wrong, or the program crashes.



5. Go back to the main storyboard file and "Control + Drag" from the tableview to the view controller and select "data source" and "delegate". This is how you tell the tableview where it is going to get it's data from, and if an event (a touch event for example) happens, who should it notify.


6. Now click on a tableview cell and click on the right side bar and go to the fourth panel from the left. In the field Identifier type "Cell". This is label so that you can reuse tableview cells which saves memory.


7. In the ViewController.m file implement these protocol methods.
Note: Philosophically it would make sense that you would needs to implement these methods to have create an actually tableview. You need to know 1) how many rows should you have and 2) what should you label these rows and 3) what to do when a user clicks on it.

Debugging Tip: Manually label the cells at first to make sure you made your connections correctly. I once spent three hours of my life trying to figure out why my tableview was empty. Save yourself the misery.



After you implement those methods it should look like this. I changed the table to states because I wanted to later show how to alphabetize a list of states.


8. Go back to the main storyboard file and drag and drop a View Controller object, and in the right panel type "detail" and the Identifier. This will be the detail view controller to push another view onto the view controller.


9. Go to File > New File > UIViewController Subclass and then create a UIViewController subclass called "DetailViewController" and unselect use XIB for interface.



10. Go back to the main storyboard file and in the right panel change the class of your newest view controller to be the "DetailViewController" that you just created.


11. Now go back to the ViewController.h file and then add "#import DetailViewController.h" at the top of your file. Then edit the two methods like below.

Note: What's new in iOS 5 is the storyboard and transitioning from one view to the other. Instead of having lots of Xib files, you replace them with views all placed into one storyboard file. This makes life much easier for the developer. So seen below is how you create a view controller object in storyboard.
"[self.storyboard instantiateViewControllerWithIdentifier:@"detail"" tells the computer to create the view that I called "detail" in the storyboard file, and then the "[self.navigationController pushViewController:detail animated:YES]" then pushes the view onto the view stack, so the visible view is then the current view.

Note: The tableview height method is self-explanatory. For some reason I had a hard time finding that method when I first started so I thought I would include it here for people to play with.


If everything is working correctly you should see these two screens if you select onto a tableview cell.

Note: In keeping with the states them I added two label to the detail view to work with later on.




12. Now if you can add a background image to the tableview cell by editing the cellForRowAtIndexPath method. Here I have a 320x65 pixel image called "LightGrey.png" which I'll include in the project at the end of the tutorial. Adding a background image really adds vibrance to your tableview.





13. Create a datasource by editing your ViewController.h and ViewController.m files so they match the ones below.
















Then make these changes in the ViewController.m file:



Changes:
1) @synthesize states and datasource.
2) In the viewDidLoad method call the function setupArray;
3) Create the datasource in setupArray;
4) Change the text label so that it reads from the datasource.

14. Edit the DetailViewController.h file so it matches the one below.



Then @synthesize them at the top of the DetailViewController.m file.


Then edit the viewDidLoad method.


15. Go back to the main storyboard file and select the detail view controller and "Control + Drag" from the DetailViewController to each of the UILabels and connect them to the appropriate outlet. 








16. Then go back to the ViewController.m file and edit the didSelectRowAtIndexPathMethod so it matches the following. This is just passing data from one view to the other.

So now when you select the state, the detail view will show the state's name and the state capital.