Thursday, October 3, 2013

iOS 7 (XCode 5) Tutorial - ContentSize of Text View is not calculating correctly any more with iOS 7

iOS 7 (XCode 5) ContentSize of Text View is not calculating correctly any more with iOS 7


Before X Code 5, to get the contents height of text view we use text view's property contentSize. But its no longer work with new iOS 7. 

Option 1:

With iOS 7, we have a different property named textContainer. It gives text container of text view. 

You need to replace the following line of code (These line of code set the text view frame according to its content length.)

 CGRect frame = _textView.frame;
 frame.size.height = _textView.contentSize.height;
_textView.frame = frame;

with 

CGRect frame = _textView.frame;
 frame.size.height = _textView.textContainer.size.height;
 _textView.frame = frame;

_textView.textContainer.size gives the same value which was given by _textView.contentSize earlier.

Option 2:

We can also replace the line of code 


 CGRect frame = _textView.frame;
 frame.size.height = _textView.contentSize.height;
_textView.frame = frame;

with 

CGRect frame = _textView.frame;
 frame.size.height = [_textView sizeThatFits:CGSizeMake(txtView.frame.size.width, MAXFLOAT)].height;
 _textView.frame = frame;

Above lines of code will work with each iOS.






Monday, September 30, 2013

iOS 7 ( XCode 5) Tutorial - IBAction is not working with custom cell

iOS 7 ( XCode 5) IBAction is not working with custom cell


Many of the developer used custom view to show custom cell on Table view for older version of iOS. If you are one of them, then you will have to face a problem that your button click action will no longer work with iOS7.


How to resolve this:

You have three options:

Option 1:  Create the new lay out with new table cell instead of taking view. and put all layouts again in table cell.

I know, this will require a lot of effort. If you don't want to do this, we have a very small hack for it : option 2


Option 2: Create a IBOutlet for your button and add this button as a subview of your cell's content view.


    [self.myCell.contentView addSubview:self.btn_click];


The above line of code will add btn_click as a subview of you content view. Now button click action should work.

Option 3: 

The best way : 

i) Take An outlet UITableViewCell.
ii) Make existing view as subview of new table cell.
iii) Disconnect the connection of custom cell to existing view and connect it to new UITableViewCell.

thats it, Your IBAction will work now.

May be you got the crash with error message that "class is not key value coding - compliant.". Check your old view connection and remove all connection having yellow mark.

Please don't hesitate to use comment section if you have any question.




Tuesday, January 29, 2013

Custom KeyBoard Handler With Done, Next and Previous Button



Keyword: Safari like keyboard, done, next button, tab orderring, text field, text field delegate

Custom KeyBoard Handler With Done, Next and Previous Button

Get contacts of all your emergency needs on single tap. Download Quick-Finder for iPhone


Get the sample code and helper file from the link

1) Copy helper files customKeyBoardHelper.h and customKeyBoardHelper.m to your project.
2) Follwing methods are provided in helper classes

  -(void)showingKeyboardHeader:(BOOL)isKeyboard;
  -(void)showingDoneButton:(BOOL)isDone;
  -(void)settingTitleForDoneButton:(NSString *)done WithImage:(UIImage *)dimg;


  -(void)addButtonWithTitle:(NSString *)tit forCustomHandler:(SEL)sel;
  -(void)addButtonWithImage:(UIImage *)img forCustomHandler:(SEL)sel;


  -(void)addButtonWithTitle:(NSString *)tit forEvent:(events)sel;
  -(void)addButtonWithImage:(UIImage *)img forEvent:(events)sel;


  -(void)addTextField:(UITextField *)txtField;
  -(void)getCustomeKeyBoard;
  -(id)initWithBaseController:(UIViewController *)ctrl;



Use of Helper Classes


1) Take a project of name KeyBoardSample.

2) Open KeyBoardSample.xib and populate 4 text fields on it. 

3) Named these as txt1,txt2,txt3 and txt4.

4) Connect all text fields outlets to .h File.

5) import customKeyBoardHelper.h to KeyBoardSample.h

5) Open .m file and modified the code of  viewDidLoad as 


- (void)viewDidLoad
{
    [super viewDidLoad];
    
    customKeyBoardHelper *helper=[[customKeyBoardHelper alloc]initWithBaseController:self];
    [helper addTextField:self.txt1];
    [helper addTextField:self.txt3];
    [helper addTextField:self.txt2];

//  Here tab order is txt1 --> txt3 --> txt2 . You can change it.

    [helper addButtonWithTitle:@"Next" forEvent:MoveToNext];

// Two methods are provided. MoveToNext and MoveToBack
//  MoveToNext method is used to move cursor from one text field to next field.
//  MoveToBack method is used to move cursor from one text field to previous field.

   [helper addButtonWithTitle:@"Test" forCustomHandler:@selector(testtask)];

// You can also make your custom handler. Here we have made a method named testtask. We need to implement this method later.

// You can also set the image instead of giving title as 

 [helper addButtonWithImage:[UIImage imageNamed:@"imageName.png"] forEvent:MoveToNext];
   
// Finally call the method to set your custom key board.   
    [helper getCustomeKeyBoard];
}


6) implement testtask method.

-(void)testtask
{



}

7) Done button is provided by default. You can hide this by using method showingDoneButton.


Get the sample code and helper files at   
http://adf.ly/IArVQ









Sunday, January 13, 2013

iPhone Post Web Service Helper

POST SERVICE HELPER 

Keywords: Post service, HTTP, Helper

Get contacts of all your emergency needs on single tap. Download Quick-Finder for iPhone

Helper classes download at http://adf.ly/ILKC0


1)  Get the helper classes for post service from here. This helper class provides asynchronous request.

2) Methods provided by helper classes

  -(void)setURL:(NSString *)str;
  -(void)addParamValue:(NSString *)value forKey:(NSString *)key;
  -(void)addHeaderValue:(NSString *)value forKey:(NSString *)key;
  -(void)runWithController:(UIViewController *)ctrl andCallBack:(SEL)select;


Use of helper classes


i) import Post service helper class where do you want to use post service
        #import "PostServiceHelper.h"

ii) Initialise object of PostServiceHelper as 
      PostServiceHelper *helper=[[PostServiceHelper alloc]init];

iii) set URL as 

    [helper setURL:urlString];

    // url string is your url where do you want to send request.



iv) set Header as 
      [helper  addHeaderValue:value forKey:key];
      // value and key are NSString 

v) set Parameter as
     [helper addParamValue:value forKey:key];
     // value and key are NSString 

vi) Run service
    [helper runWithController:self andCallBack:@selector(callback:)];
  // callback: is a callback method


vii) You can use call back method as  

-(void)callback:(NSString *)result
{
        NSLog(@"%@", result);
// Here we are printing response , You can use this result as you want

 }

You can get the source file from here






Sunday, December 30, 2012

How to show rout map in iOS6

Key Words: Google Map, iOS6, rout map
  

              How to show rout map in iOS6

Get contacts of all your emergency needs on single tap. Download Quick-Finder for iPhone


1) Take a web view where do you want to show the map.

2) Let you want to show the rout between Delhi(India) to Noida(India).

   You need to write following code of lines
   
   NSString *mapStr=[NSString stringWithFormat:@"https://maps.google.com/maps?saddr=delhi&   daddr=noida"];
    NSURL *mapURL=[NSURL URLWithString:mapStr];
    NSURLRequest *mapReq=[NSURLRequest requestWithURL:mapURL];
    [webView loadRequest:mapReq]; 


If you know the lattitude and longitude of given places you can use pair of (lat, long) instead of name of places.


Tuesday, December 25, 2012

How To Make Gallery View in iOS

Keywords: Scroll view, gallery, ios, iphone, xcode, image view

How To Make Gallery View in iOS

Get contacts of all your emergency needs on single tap. Download Quick-Finder for iPhone

Code of this sample is available here
http://adf.ly/GS9Ya



1) Take a project of name GallerySample.

2) drag and drop 5 images in your resource folder with name of image1.jpeg,image2.jpeg,image3.jpeg,image4.jpeg and image5.jpeg.

3) Open ViewController.m and modified the code as follows (Modified code is in different color)


#import "ViewController.h"

@interface ViewController ()

@end

@implementation ViewController

- (void)viewDidLoad
{
    [super viewDidLoad];
    
    
    UIScrollView *scrollView=[[UIScrollView alloc]initWithFrame:CGRectMake(0, 50, 320, 270)];
    // creating a scroll view
    
    
    [scrollView setPagingEnabled:YES];
    
    // enabled paging of scroll view
    
    [scrollView setShowsHorizontalScrollIndicator:NO];
    
    // disabled sliding bar
    
    NSArray *imageArray=[[NSArray alloc]initWithObjects:@"image1",@"image2",@"image3",@"image4",@"image5", nil];
    
    // creating an array having the name of all images which are to be shown in gallery
    
    
    
    for( int i=0; i< [imageArray count];i++)
    {
        
        NSString *imageName=[imageArray objectAtIndex:i];
    
        // getting the name of image from array
        
        NSString *fullImageName=[NSString stringWithFormat:@"%@.jpeg",imageName];
        
        // appending extention to the name of image to complete the image name
        
        int padding=25;
        // padding is given.
        
        CGRect imageViewFrame=CGRectMake(scrollView.frame.size.width*i+padding, scrollView.frame.origin.y, scrollView.frame.size.width-2*padding, scrollView.frame.size.height);
        
        // Getting frame of image so that all images are not overlapped to each other.
        // each frame is distict with other frame
        
        UIImageView *imageView=[[UIImageView alloc]initWithFrame:imageViewFrame];
        
        // Setting frame of imageView
        
        [imageView setImage:[UIImage imageNamed:fullImageName]];
        
        // setting image to the image view
        
        [imageView setContentMode:UIViewContentModeScaleAspectFit];
        
        // setting content mode of image view so that image looks good
        
        
        [scrollView addSubview:imageView];
        
        // adding image view to the scroll view

    }
    
    CGSize scrollViewSize=CGSizeMake(scrollView.frame.size.width*[imageArray count], scrollView.frame.size.height);
    
    // getting the content size of scroll view
    
    [scrollView setContentSize:scrollViewSize];
    // setting content size of scroll view
    
    [self.view addSubview:scrollView];
    
    // finally add scroll view to your view
}

- (void)didReceiveMemoryWarning
{
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

@end


Now when you run the code you will get a gallery having 5 images , You can scroll to get all images.

You can download the sample code from here (Media fire link)
http://adf.ly/GS9Ya


Friday, November 30, 2012

How to store values in keychain of ios

How to store values in keychain of ios

Get contacts of all your emergency needs on single tap. Download Quick-Finder for iPhone

Tutorial for: Key chain, user defaults, values, KeychainItemWrapper, iphone, ios

What is keyChain -

Key chain is the place where we can store the values which will be retain even after deleting application. Generally we store username and password in it.


Difference between KeyChain and userDefaults
The values which are store in userDeafults are deleted when we delete the app from our device but the values stored in KeyChain will not.


Apple provides helper classes, for that you can refer to this link
htps://developer.apple.com/library/ios/#samplecode/GenericKeychain/Introduction/Intro.html#//apple_ref/doc/uid/DTS40007797
Or you can download it from here

Initialise the class

KeychainItemWrapper *wrapper = [[KeychainItemWrapper alloc] initWithIdentifier:@"Your application name" accessGroup:nil];

How to save the values
[wrapper setObject:@"PASSWORD" forKey:@"KEYPASS"];
[wrapper setObject:@"USERNAME" forKey:@"KEYUSER"];


how to retrive the values

NSString *pwd = [wrapper objectForKey:@"KEYPASS"];
NSString *user = [wrapperobjectForKey:@"KEYUSER"];


How to delete the values

[wrapper resetKeychainItem];

Reference: http://stackoverflow.com/questions/6972092/ios-how-to-store-username-password-within-an-app
www.Hypersmash.com

Thursday, November 29, 2012

How to implement hot search on tableView in iPhone

Keyword: Search bar, table view, iphone, ios, hot search, instant search, delegate, datasource, implement,



Get contacts of all your emergency needs on single tap. Download Quick-Finder for iPhone

       How to implement hot search on tableView in iPhone


You can download the source code from here


1)   Take a new project named TableSearch

2)  Add Table in viewController.xib named tbl;

3) Add a search bar named searchBar

4) Set UITableViewDataSource,UITableViewDelegate and UISearchBarDelegate to support Delegate methods.

4) Modify the code of ViewController.h (Modified code is in different color - brown )

#import <UIKit/UIKit.h>

@interface ViewController : UIViewController <UITableViewDataSource,UITableViewDelegate,UISearchBarDelegate,UITextFieldDelegate>
{
    NSMutableArray *tableArray; // stores all data 
    NSMutableArray *filterArray; // stores only searched data 
    NSMutableArray *displayArray; // shows data on table
}
@property (retain, nonatomic) IBOutlet UISearchBar *serchBar;
@property (retain, nonatomic) IBOutlet UITableView *tbl;

@end


4)Now modify the code of ViewController.m (Modified code is in different color - brown )



import "ViewController.h"

@implementation ViewController
@synthesize serchBar;
@synthesize tbl;
//
//
// Method to filter the data from total array with key, this method returns filtered array
//
//
-(NSMutableArray *)managingDisplayArrayFromArray:(NSMutableArray *)totalArray withKey:(NSString *)key
{
    NSMutableArray *ary=[[NSMutableArray alloc]init];
    key=[key lowercaseString];
    for (NSString *str in totalArray)
    {
      NSRange range = [str rangeOfString:key];
         if (range.location != NSNotFound )
             [ary addObject:str];
    
    }
    return ary;
}


// Implementation of textFiled delegate method
// This method will call on every type on text field of serach bar


-(BOOL)textField:(UITextField *)textField shouldChangeCharactersInRange:(NSRange)range replacementString:(NSString *)string
{
    NSString *keyString=[textField.text stringByAppendingString:string];
    displayArray=[self managingDisplayArrayFromArray:tableArray withKey:keyString];
    [self.tbl reloadData];
    return YES;
}


// Implementation of searchBar delegate method
// This method will call on search button click

- (void)searchBarSearchButtonClicked:(UISearchBar *)searchBar
{
    displayArray=[self managingDisplayArrayFromArray:tableArray withKey:serchBar.text];
    [self.tbl reloadData];
    [self.serchBar resignFirstResponder];

}

// Implementation of searchBar delegate method
// This method will call on cancle button click

-(void)searchBarCancelButtonClicked:(UISearchBar *) searchBar
{
    displayArray=tableArray;
    [self.tbl reloadData];
    [self.serchBar resignFirstResponder];

}
#pragma mark -- Implementation of table view delegate methods

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    return [displayArray count];
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
     UITableViewCell *cell=[[UITableViewCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"Cell"];
    [cell.textLabel setText:[displayArray objectAtIndex:indexPath.row]];
    return cell;
}



- (void)viewDidLoad
{
    [super viewDidLoad];
    
    // Initializing the arrays
    
    tableArray=[[NSMutableArray alloc]init];
    displayArray=[[NSMutableArray alloc]init];
    [tableArray addObject:@"ram"];
    [tableArray addObject:@"shyam"];
    [tableArray addObject:@"suresh"];
    [tableArray addObject:@"girjesh"];
    [tableArray addObject:@"sudhir"];
    [tableArray addObject:@"aknsha"];
    [tableArray addObject:@"vineeta"];
    [tableArray addObject:@"rakesh"];
    [tableArray addObject:@"himanshu"];
    [tableArray addObject:@"barkha"];
    displayArray=[NSMutableArray arrayWithArray:tableArray];
    self.serchBar.showsCancelButton=YES;
    
  // Following 3 line of code is written to support text field of searchBar and also here we are setting  delegate of that text filed
    
    
    NSArray *subViewsArray=[self.serchBar subviews]; 
    UITextField *txtField=(UITextField *)[subViewsArray objectAtIndex:1];
    txtField.delegate=self;

// Do any additional setup after loading the view, typically from a nib.
}

- (void)didReceiveMemoryWarning
{
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

- (void)dealloc {
    [serchBar release];
    [tbl release];
    [super dealloc];
}
@end


You can also download the code from here

Link for Source code http://adf.ly/FRVuX




Tuesday, November 27, 2012

How To Use shouldAutoRotate With Tab Bar controller in iOS6

Keyword: ios6, tab bar controller, delegate, rotation, category,should Autoraotate, interface orientatio


 Get contacts of all your emergency needs on single tap. Download Quick-Finder for iPhone

How To Use shouldAutoRotate With Tab Bar controller in iOS6



To Support tabBarController auto Rotation in iOS6. You need to make category for that.


Add new file in you project named UITabBarController+autoRotate. File should be subclass of NSObject.




Modified the code of  UITabBarController+autoRotate.h as 




#import <UIKit/UIKit.h>

@interface UITabBarController (autoRotate)<UITabBarControllerDelegate>

-(BOOL)shouldAutorotate;
- (NSUInteger)supportedInterfaceOrientations;

@end


And Modified the code of  UITabBarController+autoRotate.m as 






#import "UITabBarController+autoRotate.h"
#import "AppDelegate.h"// 


@implementation UITabBarController (autoRotate)

-(BOOL)shouldAutorotate {
    
    AppDelegate *delegate= (AppDelegate*)[[UIApplication sharedApplication]delegate];
    return [delegate.tabBarController.selectedViewController shouldAutorotate];
}


- (NSUInteger)supportedInterfaceOrientations {
    return UIInterfaceOrientationMaskAll;
}

@end

Thats it.

Note: you may have to change name of AppDelegate With your Project AppDelegate name.

Feel free to use comment section



Friday, November 23, 2012

How to show table having alphabetical ordered section

Keyword: ios6, table view, delegate,datasource, rotation, category,should Autoraotate, interface orientation, dictionary, section, cell, reuse identifier, iphone,sample project 

Get contacts of all your emergency needs on single tap. Download Quick-Finder for iPhone

How to show table having alphabetical ordered section


1) Create a new project name TableSample.

2) Open ViewController.xib and paste a tableView on it . Make the IBOutlet of it as 

     @property (retain, nonatomic) IBOutlet UITableView *tbl;

and also synthesize it.

3) Now Attach datasource and delegate of tableView with File owner.

4) Now open ViewController.h as (Modified code is in different color) 


#import <UIKit/UIKit.h>

@interface ViewController : UIViewController<UITableViewDataSource,UITableViewDelegate>

@property (retain, nonatomic) IBOutlet UITableView *tbl;
@property (nonatomic,retain) NSMutableDictionary *tblDictionary;
@property (nonatomic,retain)NSMutableArray *keyArray;
@property (nonatomic,retain)NSMutableArray *tableArray;
@property (nonatomic,retain)NSMutableArray *filteredArray;
@end






5) Now open ViewController.m

  implement the following method

  i) - (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section

   // This method is used to create headers of section

 ii)   -(NSInteger)numberOfSectionsInTableView:(UITableView *)tableView


// This method is used to define number of sections

iii)- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section

// This method is used for number of rows in each section


we are using a custom method that fill the values of array in dictionary.



6) Now Modified The code of ViewController.m as




#import "ViewController.h"

@interface ViewController ()

@end

@implementation ViewController
@synthesize tableArray;
@synthesize filteredArray;
@synthesize tblDictionary;
@synthesize keyArray;


- (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section
{
    UIView *header=[[UIView alloc]initWithFrame:CGRectMake(0, 0, 320, 20)];
    [header setBackgroundColor:[UIColor blackColor]];
    UILabel *lbl=[[UILabel alloc]initWithFrame:CGRectMake(20, 0, 320, 20)];
    [header addSubview:lbl];
    [lbl setTextColor:[UIColor whiteColor]];
    [lbl setBackgroundColor:[UIColor clearColor]];
    [lbl setText:[keyArray objectAtIndex:section]];
    return header;


}

-(NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
    return  [keyArray count];
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{

    NSArray *ary=[self.tblDictionary valueForKey:[keyArray objectAtIndex:section]];
    return [ary count];

}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    UITableViewCell *cell=[[UITableViewCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"Cell"];
    NSString *key=[keyArray objectAtIndex:[indexPath section]];
    NSArray *array=(NSArray *)[self.tblDictionary valueForKey:key];
    NSString *cellTitle=[array objectAtIndex:[indexPath row]];
    [cell.textLabel setText:cellTitle];
    return cell;
}

-(NSMutableDictionary *)fillingDictionary:(NSMutableArray *)ary
{

// This method has the real magic of this sample

    keyArray=[[NSMutableArray alloc]init];
    [keyArray removeAllObjects];
    
    NSMutableDictionary *dic=[[NSMutableDictionary alloc]init];
    
    // First sort the array
    
    [ary sortUsingSelector:@selector(compare:)];
    
    
    // Get the first character of your string which will be your key
    
    for(NSString *str in ary)
    {
        char charval=[str characterAtIndex:0];
        NSString *charStr=[NSString stringWithUTF8String:&charval];
        if(![keyArray containsObject:charStr])
        {
            NSMutableArray *charArray=[[NSMutableArray alloc]init];
            [charArray addObject:str];
            [keyArray addObject:charStr];
            [dic setValue:charArray forKey:charStr];
        }
        else
        {
            NSMutableArray *prevArray=(NSMutableArray *)[dic valueForKey:charStr];
            [prevArray addObject:str];
            [dic setValue:prevArray forKey:charStr];
        
        }
    
    }
    return dic;

}

- (void)viewDidLoad
{
    [super viewDidLoad];
    NSMutableArray *ary=[[NSMutableArray alloc]init];
    [ary addObject:@"gfwfhlr"];
    [ary addObject:@"irofhqrlo"];
    [ary addObject:@"gfwtgfhlr"];
    [ary addObject:@"gegirofgewghqrlo"];
    [ary addObject:@"dsfgverg"];
    [ary addObject:@"gergqrlo"];
    [ary addObject:@"gregerg"];
    [ary addObject:@"gegqrlo"];
    [ary addObject:@"getwgtgt"];
    [ary addObject:@"uyuqrlo"];
    [ary addObject:@"hmnjmj"];
    [ary addObject:@"mjhmghqrlo"];
    [ary addObject:@"mjmjm"];
    [ary addObject:@"irofhmjmjqrlo"];
    [ary addObject:@"sgfwfhlr"];
    [ary addObject:@"daimrofh;qrlo"];
    [ary addObject:@"fgfwfhlr"];
    [ary addObject:@"girofhqrlo"];
    [ary addObject:@"hgfwfhlr"];
    [ary addObject:@"jirofhqrlo"];
    [ary addObject:@"kgfwfhlr"];
    [ary addObject:@"lirofhqrlo"];
    
    self.tblDictionary =[self fillingDictionary:ary];
    [self.tbl reloadData];
    
  // Do any additional setup after loading the view, typically from a nib.
}

- (void)didReceiveMemoryWarning
{
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

- (void)dealloc {
    [_tbl release];
    [super dealloc];
}
@end

You can also download the code from here

or click to link http://adf.ly/FBhKI







Thursday, November 22, 2012

How to show user current city name

Keyword: ios6, Core Location frame work, iphone,sample project, CLLocationManagerDelegate, CLLocationManager, startUpdatingLocation, setDesiredAccuracy,map

Get contacts of all your emergency needs on single tap. Download Quick-Finder for iPhone


How to show user current city name



1) Create a new Project with name of CityFinder and 
2) add FrameWork CoreLocation.FrameWork


3) Update the code of AppDelegate.h as follows ( Modified code is in different color - yellow )


#import <UIKit/UIKit.h>
#import <CoreLocation/CoreLocation.h>

@class ViewController;

@interface AppDelegate : UIResponder <UIApplicationDelegate,CLLocationManagerDelegate>

@property (strong, nonatomic) UIWindow *window;
@property (strong, nonatomic) ViewController *viewController;
@property (nonatomic,retain) CLLocationManager *manager;
@property float latitude;
@property float longitude;




4) Synthesize all variables

@synthesize manager;
@synthesize latitude;
@synthesize longitude;








5) Update the code of method didFinishLaunching in AppDelegate.m as follows

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
    self.window = [[[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]] autorelease];
    // Override point for customization after application launch.
    self.viewController = [[[ViewController alloc] initWithNibName:@"ViewController" bundle:nil]   autorelease];
    self.window.rootViewController = self.viewController;
    
    self.manager=[[CLLocationManager alloc]init];
    [self.manager setDistanceFilter:CLLocationDistanceMax];
    [self.manager setDelegate:self];
    [self.manager setDesiredAccuracy:kCLLocationAccuracyBest];
    [self.manager startUpdatingLocation];
    [self.window makeKeyAndVisible];

    return YES;
}




6) Update xib of ViewController

   i) add a text view named txtView;
  ii) add an button and also an IBAction with it named  - (IBAction)clickToGetLocation:(id)sender


7) update the code of ViewController.h
   

    #import <UIKit/UIKit.h>

    @interface ViewController : UIViewController

    @property (retain, nonatomic) IBOutlet UITextView *txtView;
    - (IBAction)clickToGetLocation:(id)sender;
   @end

  

8) Code of click action 


- (IBAction)clickToGetLocation:(id)sender {
    
    AppDelegate *delegate=(AppDelegate *)[[UIApplication sharedApplication]delegate];
    
    NSString *urlString = [NSString stringWithFormat:@"http://maps.google.com/maps/geo?q=%f,%f&output=csv",delegate.latitude, delegate.longitude];
    NSError* error;
    NSString *locationString = [NSString stringWithContentsOfURL:[NSURL URLWithString:urlString] encoding:NSASCIIStringEncoding error:&error];
    locationString = [locationString stringByReplacingOccurrencesOfString:@"\"" withString:@""];
    self.txtView.text=[locationString substringFromIndex:6];
}






Now thats it 

Click on button. You will get current location on text View.



Note:   If you are running this code on simulator you will get address  "1 stockton st,francisco, ca 94108 usa"  default location of simulator . You need to run this code on real device to get the current location.




You can also download the sample code from here


  http://adf.ly/F9ECK


If you have any question, please put it in comment section.