Introduction
In this article I will create a Single View application. Here we add one more view from Cocoa Touch for implementing a map and add one more Objective-C class for implementing an annotation pin. In the first view here we add a table from outlet. In another view a map on delegate event of the table view or a notation pin on a particular location (that is passed by table) is shown.
To better understand we use the following procedure.
Step 1
Open Xcode by double-clicking on it.
Step 2
Create a New XCode Project by clicking on it.
Step 3
Now Select Single View Application and click on "Next".
Step 4
Now provide your Product Name and Company Identifier.
Step 5
Select the location where you want to save your project and click on "Create".
Step 6
First we add the framework MkMapkit that is required to show the location.
To import this framework we use the following.
Step 7
Click on project and select "Build Phase".
Step 8
Click on the "+" icon to add a framework.
Step 9
At last click on the "Add" button to import the framework into the project.
Step 10
Now we write the code.
mapAppDelegate.h
//
// mapAppDelegate.h
// TableMap
//
// Created by Sachin Bhardwaj on 19/01/13.
// Copyright (c) 2013 Sachin Bhardwaj. All rights reserved.
//
#import <UIKit/UIKit.h>
@class mapViewController;
@interface mapAppDelegate : UIResponder <UIApplicationDelegate>
{
UINavigationController *nav;
}
@property (strong, nonatomic) UINavigationController *nav;
@property (strong, nonatomic) UIWindow *window;
@property (strong, nonatomic) mapViewController *viewController;
@end
mapAppDelegate.m
//
// mapAppDelegate.m
// TableMap
//
// Created by Sachin Bhardwaj on 19/01/13.
// Copyright (c) 2013 Sachin Bhardwaj. All rights reserved.
//
#import "mapAppDelegate.h"
#import "mapViewController.h"
@implementation mapAppDelegate
@synthesize nav;
- (void)dealloc
{
[_window release];
[_viewController release];
[super dealloc];
}
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
// Override point for customization after application launch.
self.viewController = [[mapViewController alloc] initWithNibName:@"mapViewController" bundle:nil];
nav=[[UINavigationController alloc]initWithRootViewController:_viewController];
self.window.rootViewController=nav;
[self.window makeKeyAndVisible];
return YES;}
- (void)applicationWillResignActive:(UIApplication *)application
{// Sent when the application is about to move from active to inactive state. This can occur for certain types of temporary interruptions (such as an incoming phone call or SMS message) or when the user quits the application and it begins the transition to the background state.// Use this method to pause ongoing tasks, disable timers, and throttle down OpenGL ES frame rates. Games should use this method to pause the game.}
- (void)applicationDidEnterBackground:(UIApplication *)application{
// Use this method to release shared resources, save user data, inalidate timers, and store enough application state information to restore your application to its current state in case it is terminated later.
// If your application supports background execution, this method is called instead of applicationWillTerminate: when the user quits.}
- (void)applicationWillEnterForeground:(UIApplication *)application
{// Called as part of the transition from the background to the inactive state; here you can undo many of the changes made on entering the background.}
- (void)applicationDidBecomeActive:(UIApplication *)application{// Restart any tasks that were paused (or not yet started) while the application was inactive. If the application was previously in the background, optionally refresh the user interface.}
- (void)applicationWillTerminate:(UIApplication *)application{// Called when the application is about to terminate. Save data if appropriate. See also applicationDidEnterBackground:.}
@end
mapViewController.h
//
// mapViewController.h
// TableMap
//
// Created by Sachin Bhardwaj on 19/01/13.
// Copyright (c) 2013 Sachin Bhardwaj. All rights reserved.
//
#import <UIKit/UIKit.h>
#import "locationViewController.h"
@interface mapViewController : UIViewController
{
IBOutlet UITableView *table;
NSMutableArray *loaction;
NSMutableArray *name;
NSArray *imgplace;
}
@property (nonatomic,strong) UITableView *table;
@property (nonatomic,strong) NSMutableArray *loaction;
@property (nonatomic,strong) NSArray *imgplace;
@property (nonatomic,strong) NSMutableArray *name;
@end
ViewController.m
//
// mapViewController.m
// TableMap
//
// Created by Sachin Bhardwaj on 19/01/13.
// Copyright (c) 2013 Sachin Bhardwaj. All rights reserved.
//
#import "mapViewController.h"
@interface mapViewController ()
@end
@implementation mapViewController
@synthesize table,loaction,imgplace,name;
- (void)viewDidLoad
{
[super viewDidLoad];
//array=[[NSArray alloc]init];
self.loaction = [NSMutableArray arrayWithObjects:@"New Delhi", @"Jaipur", @"Bangalore", @"Mumbai", nil];
// imgplace=[[NSArray alloc]init];
imgplace = [NSArray arrayWithObjects:@"New Delhi.jpg", @"Jaipur.jpeg", @"Bangalore.jpeg", @"Mumbai.jpeg", nil];
self.name = [NSMutableArray arrayWithObjects:@"Nikhil",@"Sachin",@"Sajid",@"Rahul",nil];
self.title=@"City Name's";
// Do any additional setup after loading the view, typically from a nib.
}
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{//#warning Potentially incomplete method implementation.
// Return the number of sections.
return 1;
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{//#warning Incomplete method implementation.
// Return the number of rows in the section.
return [self.loaction count];
}
- (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.textLabel.text=[self.array objectAtIndex:[indexPath row]];
// UIImage *cellImage = [UIImage imageNamed:@"Audi.jpg"];
// cell.imageView.image = cellImage;
cell.textLabel.text = [NSString stringWithFormat:@"%@,%@",[self.name objectAtIndex:indexPath.row],[self.loaction objectAtIndex:indexPath.row]];
cell.imageView.image = [UIImage imageNamed:[imgplace objectAtIndex: indexPath.row]];
return cell;
}
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
NSLog(@"working");
locationViewController *my = [[locationViewController alloc] init];
my.strpath =[loaction objectAtIndex:indexPath.row];
[self.navigationController pushViewController:my animated:YES];
}
- (void)viewDidUnload
{
[super viewDidUnload];
}
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
return (interfaceOrientation != UIInterfaceOrientationPortraitUpsideDown);
}
@end





Sachin BhardwajPosted Feb 2, 2013, 2:37 AM
Thanks prince
prince johnPosted Feb 2, 2013, 12:08 AM
nice article