Monday, 23 February 2015

Core Data

Core Data


Core Data is not a Database

When we talk about persistent data, people probably think of database. If you are familiar with Oracle or MySQL, you know that relational database stores data in the form of table, row and column, and it usually facilitates access through what-so-called SQL query. However, don’t mix up Core Data with database. Though Sqlite database is the default persistent store for Core Data on iPhone, Core Data is not a relational database. It is actually a framework that lets developers store (or retrieve) data in database in an object-oriented way. With Core Data, you can easily map the objects in your apps to the table records in the database without even knowing any SQL.
To illustrate the concept, let’s begin and create your first app using Core Data. This app is called My Store. It is a very simple app that stores all devices you have by collecting the name, version,company.
MyStore App using Core Data
MyStore App using Core Data

Creating a Sample App with Core Data

First let’s create a project with Core Data. Open Xcode and create a new Project, choose the templateEmpty Application as shown below.
Create a New Project with Empty Application Template
Create a New Project with Empty Application Template
At the next screen, enter MyStore as a name of the project, select iPhone in Devices family and don’t forget to select the options Use Storyboards, Use Core Data, Use Automatic Reference Counting. Press next and create.
MyStore Xcode Project Options
Set up Xcode Project Options – Remember to select Use Core Data

Defining Managed Object Model

Let’s move on to build the app. The first step is to open the Data Model named MyStore.xcdatamodeldand define the object model. Here we’ll define a Device entity that will be used to store the device information to database. To create an entity, click the + button in the bottom-left of the editor view and name the entity as Device.
Managed Object Model - Add Entity
Add Device entity in the model
Once you create a new entity, you need to add attributes to it. Click on the + button in the attributes section to do that. Add three attributes including name, version and company. Set the type as String.
MyStore Add Entity
Add 3 Attributes (company, name and version) to the Device entity

Designing the User Interface

Note: While we encourage you to build the user interface, you can also skip the procedures anddownload the project template from here. The template already comes with the Storyboard and set up all the view controller classes for you. This gives you a good starting point to work on Core Data. If you use the template, you can skip this section and go directly to the “Diving Core Data” section.
The next thing we need to do is to create the Storyboard that defines the views of our app. Navigate to File > New > New File and choose Storyboard in the User Interface template. Click next and select the iPhone device family, click create.

Creating the Storyboard
Creating the Storyboard
Once created, make sure to set the “Storyboard” you’ve just created as the main storyboard in the project setting.
MyStore Set Main Storyboard
Set the Storyboard you just created as the Main Storyboard
Also don’t forget to delete all the generated code in the method -(BOOL)application:application didFinishLaunchingWithOptions:launchOptions inside the AppDelegate file. The method should be as simple as this:
1
2
3
4
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
    return YES;
}
Go to Storyboard and create the user interface like below:
MyStore - Storyboard
MyStore App – Storyboard
First, drag a Table View Controller and embed it in a Navigation Controller. Drag a button to the top-right part of navigation bar and set the identifier as “Add”. This will automatically change the button to a “+” button. Next, select the prototype cell and change its style to “Right Detail”.
MyStore App - Table View Controller
Creating the Table View Controller
Drag a View Controller to the Storyboard and add a Navigation Bar to the top of the screen. Next, drag two buttons into the navigation bar. Name one as “Cancel” and the other one as “Save”. In the content view, add three text fields and name the placeholder attributes as “Name”, “Version” and “Company”.
This detail view will be shown when user taps the “+” button in the table view controller. So finally, press and hold the Control key, click the “+” button and drag towards the detail view controller. Select “Modal” as the Segue action to connect the table view controller and detail view controller.
MyStore App - Detail View Design
Designing the Detail View Controller

Creating View Controller Classes

Create a new class by right-clicking on the MyStore folder > New File > Objective-C class, and name the class as DeviceViewController. Make it as a subclass of UITableViewController. Navigate to the Storyboard, select the Table View Controller and associate it with the DeviceViewController class.
MyStore - Assign DeviceViewController Class
Set the Custom Class as DeviceViewController
Once done, do the same steps to create a new class namedDeviceDetailViewControllerUIViewController. Again, go to Storyboard and set the custom class of the detail view controller as the “DeviceDetailViewController”.
Lastly, wire up the UITextFields to the DeviceDetailViewController header file and create two action methods for the save and cancel buttons respectively.
MyStore - Wire up Text Field
Creating IBOutlet and Action Methods
Your code should like this:
1
2
3
4
5
6
@property (weak, nonatomic) IBOutlet UITextField *nameTextField;
@property (weak, nonatomic) IBOutlet UITextField *versionTextField;
@property (weak, nonatomic) IBOutlet UITextField *companyTextField;

- (IBAction)cancel:(id)sender;
- (IBAction)save:(id)sender;

Diving into Core Data

With the user interface, it’s time to go into the details of Core Data. Apparently, there are a couple of areas we have to implement:
  1. Save device information in the Detail View Controller
  2. Fetch device information from persistent store (i.e. SQLite database) and populate the data into Table View Controller
We’ll look into the implementation one by one.
Then Finally Write Code Which Is Given Below:
AppDelegate.h :
#import <UIKit/UIKit.h>
#import "DeviceViewController.h"

@interface AppDelegate : UIResponder <UIApplicationDelegate>

@property (strong, nonatomic) UIWindow *window;

@property(strong,nonatomic)UINavigationController   *navobj;
@property(strong,nonatomic)DeviceViewController     *devobj;

@property (readonly, strong, nonatomic) NSManagedObjectContext *managedObjectContext;
@property (readonly, strong, nonatomic) NSManagedObjectModel *managedObjectModel;
@property (readonly, strong, nonatomic) NSPersistentStoreCoordinator *persistentStoreCoordinator;

- (void)saveContext;
- (NSURL *)applicationDocumentsDirectory;

@end

AppDelegate.m :

#import "AppDelegate.h"

@implementation AppDelegate
@synthesize navobj,devobj;

@synthesize managedObjectContext = _managedObjectContext;
@synthesize managedObjectModel = _managedObjectModel;
@synthesize persistentStoreCoordinator = _persistentStoreCoordinator;

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
    self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
    
    
    UIStoryboard *story = [UIStoryboard storyboardWithName:@"Storyboard" bundle:nil];
    
    devobj = [story instantiateViewControllerWithIdentifier:@"DeviceViewController"];
    
    navobj = [[UINavigationController alloc] initWithRootViewController:devobj];
    
    self.window.rootViewController = navobj;
    
    self.window.backgroundColor = [UIColor whiteColor];
    [self.window makeKeyAndVisible];
    return YES;
}

Storyboard.storyboard :

DeviceViewController.h :
#import <UIKit/UIKit.h>

@interface DeviceViewController : UIViewController



@property(strong,nonatomic)IBOutlet UITableView *tblobj;
@property(strong,nonatomic)NSMutableArray       *devarr;


@end

DeviceViewController.m :

#import "DeviceViewController.h"
#import "detailViewController.h"

@interface DeviceViewController ()

@end

@implementation DeviceViewController
@synthesize tblobj,devarr;

- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
    self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
    if (self) {
        // Custom initialization
    }
    return self;
}

- (void)viewDidLoad
{
    [super viewDidLoad];
// Do any additional setup after loading the view.
}

- (NSManagedObjectContext *)managedObjectContext
{
    NSManagedObjectContext *context = nil;
    id delegate = [[UIApplication sharedApplication] delegate];
    if ([delegate performSelector:@selector(managedObjectContext)])
    {
        context = [delegate managedObjectContext];
    }
    return context;
}

- (void)viewDidAppear:(BOOL)animated
{
    [super viewDidAppear:animated];
    
    devarr = [[NSMutableArray alloc] init];
    
    // Fetch the devices from persistent data store
    NSManagedObjectContext *managedObjectContext = [self managedObjectContext];
    NSFetchRequest *fetchRequest = [[NSFetchRequest alloc] initWithEntityName:@"Device"];
    self.devarr = [[managedObjectContext executeFetchRequest:fetchRequest error:nil] mutableCopy];
    
    [self.tblobj reloadData];
}

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
    // Return the number of sections.
    return 1;
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    // Return the number of rows in the section.
    return self.devarr.count;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    static NSString *CellIdentifier = @"Cell";
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier forIndexPath:indexPath];
    
    // Configure the cell...
    NSManagedObject *device = [self.devarr objectAtIndex:indexPath.row];
    
    [cell.textLabel setText:[NSString stringWithFormat:@"%@ %@", [device valueForKey:@"name"], [device valueForKey:@"version"]]];
    
    [cell.detailTextLabel setText:[device valueForKey:@"company"]];
    
    return cell;
}

- (BOOL)tableView:(UITableView *)tableView canEditRowAtIndexPath:(NSIndexPath *)indexPath
{
    // Return NO if you do not want the specified item to be editable.
    return YES;
}


- (void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath
{
    NSManagedObjectContext *context = [self managedObjectContext];
    
    if (editingStyle == UITableViewCellEditingStyleDelete) {
        // Delete object from database
        [context deleteObject:[self.devarr objectAtIndex:indexPath.row]];
        
        NSError *error = nil;
        if (![context save:&error]) {
            NSLog(@"Can't Delete! %@ %@", error, [error localizedDescription]);
            return;
        }
        
        // Remove device from table view
        [self.devarr removeObjectAtIndex:indexPath.row];
        [self.tblobj deleteRowsAtIndexPaths:[NSArray arrayWithObject:indexPath] withRowAnimation:UITableViewRowAnimationFade];
    }
}

- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
{
    if ([[segue identifier] isEqualToString:@"UpdateDevice"])
    {
        NSManagedObject *selectedDevice = [self.devarr objectAtIndex:[[self.tblobj indexPathForSelectedRow] row]];
        detailViewController *destViewController = segue.destinationViewController;
        destViewController.device = selectedDevice;
    }
}


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

@end

detailViewController.h :

#import <UIKit/UIKit.h>

@interface detailViewController : UIViewController


@property(strong,nonatomic)NSManagedObject *device;

@property (strong, nonatomic) IBOutlet UITextField *txtname;
@property (strong, nonatomic) IBOutlet UITextField *txtversion;
@property (strong, nonatomic) IBOutlet UITextField *txtcompany;

- (IBAction)savedata:(id)sender;

- (IBAction)cancel:(id)sender;


@end

detailViewController.m :

#import "detailViewController.h"

@interface detailViewController ()

@end

@implementation detailViewController
@synthesize device;

- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
    self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
    if (self) {
        // Custom initialization
    }
    return self;
}

- (void)viewDidLoad
{
    [super viewDidLoad];
    if (self.device)
    {
        [self.txtname setText:[self.device valueForKey:@"name"]];
        [self.txtversion setText:[self.device valueForKey:@"version"]];
        [self.txtcompany setText:[self.device valueForKey:@"company"]];
    }


}
- (NSManagedObjectContext *)managedObjectContext
{
    NSManagedObjectContext *context = nil;
    id delegate = [[UIApplication sharedApplication] delegate];
    if ([delegate performSelector:@selector(managedObjectContext)])
    {
        context = [delegate managedObjectContext];
    }
    return context;
}


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

- (IBAction)savedata:(id)sender
{
    
    NSManagedObjectContext *context = [self managedObjectContext];
    
    // Create a new managed object
//    NSManagedObject *newDevice = [NSEntityDescription insertNewObjectForEntityForName:@"Device" inManagedObjectContext:context];
//    [newDevice setValue:self.txtname.text forKey:@"name"];
//    [newDevice setValue:self.txtversion.text forKey:@"version"];
//    [newDevice setValue:self.txtcompany.text forKey:@"company"];
    
    if (self.device)
    {
        // Update existing device
        [self.device setValue:self.txtname.text forKey:@"name"];
        [self.device setValue:self.txtversion.text forKey:@"version"];
        [self.device setValue:self.txtcompany.text forKey:@"company"];
        
    }
    else
    {
        // Create a new device
        NSManagedObject *newDevice = [NSEntityDescription insertNewObjectForEntityForName:@"Device" inManagedObjectContext:context];
        [newDevice setValue:self.txtname.text forKey:@"name"];
        [newDevice setValue:self.txtversion.text forKey:@"version"];
        [newDevice setValue:self.txtcompany.text forKey:@"company"];
    }
    
    NSError *error = nil;
    // Save the object to persistent store
    if (![context save:&error]) {
        NSLog(@"Can't Save! %@ %@", error, [error localizedDescription]);
    }
    
    
    [self dismissViewControllerAnimated:YES completion:nil];
}

- (IBAction)cancel:(id)sender
{
    [self dismissViewControllerAnimated:YES completion:nil];
}

@end

NS User Default

NS User default


1) Set Your Storyboard Like This :




2)  Write This Following Code :

* ViewController ( Get Data From This ) 

ViewController.h :

#import <UIKit/UIKit.h>
#import "SecViewController.h"

@interface ViewController : UIViewController

{
    NSUserDefaults *def;
    
    SecViewController *secobj;
}

@property(strong,nonatomic)SecViewController *secobj;

@property(strong,nonatomic)IBOutlet UITextField *txtname;
@property(strong,nonatomic)IBOutlet UITextField *txtadd;
@property(strong,nonatomic)IBOutlet UITextField *txtno;

@property(strong,nonatomic)IBOutlet UILabel *lblname;
@property(strong,nonatomic)IBOutlet UILabel *lbladd;
@property(strong,nonatomic)IBOutlet UILabel *lblno;

-(IBAction)savedata:(id)sender;
@end

ViewController.m :

#import "ViewController.h"

@interface ViewController ()

@end

@implementation ViewController
@synthesize txtadd,txtname,txtno,lbladd,lblname,lblno,secobj;

- (void)viewDidLoad
{
    [super viewDidLoad];
    
    def = [NSUserDefaults standardUserDefaults];
}

-(IBAction)savedata:(id)sender
{
    
    [def setObject:txtname.text forKey:@"name"];
    [def setObject:txtadd.text forKey:@"add"];
    [def setObject:txtno.text forKey:@"no"];

    [def synchronize];
    
    [self getdata];
}

-(void)getdata
{
    lblname.text = [def objectForKey:@"name"];
    lbladd.text = [def objectForKey:@"add"];
    lblno.text = [def objectForKey:@"no"];
    
    UIStoryboard *story = [UIStoryboard storyboardWithName:@"Main" bundle:nil];
    
    secobj = [story instantiateViewControllerWithIdentifier:@"SecViewController"];
    
    [self.navigationController pushViewController:secobj animated:YES];
    

    

}

- (BOOL)textFieldShouldReturn:(UITextField *)textField
{
    [textField resignFirstResponder];
    return YES;
}

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

@end


* Second ViewController ( Show Data in This ) 

SecViewController.h :

#import <UIKit/UIKit.h>

@interface SecViewController : UIViewController

@property(strong,nonatomic)IBOutlet UILabel *name;
@property(strong,nonatomic)IBOutlet UILabel *add;
@property(strong,nonatomic)IBOutlet UILabel *no;

@end


SecViewController.h :

#import "SecViewController.h"

@interface SecViewController ()

@end

@implementation SecViewController
@synthesize name,add,no;

- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
    self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
    if (self) {
        // Custom initialization
    }
    return self;
}

- (void)viewDidLoad
{
    [super viewDidLoad];
    NSUserDefaults *def1 = [NSUserDefaults standardUserDefaults];
    
    name.text = [def1 objectForKey:@"name"];
    add.text = [def1 objectForKey:@"add"];
    no.text = [def1 objectForKey:@"no"];
    
}

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

@end

Place On Map using Json

Places On Map using Json


1) First of all Set Storyboard Like This :



- In First View Only Navigation Controller is here.

- In Second View There are it is simple use For Splash Screen .
   Here in secon View Controller Only Image is set.

- In Third View Controller There are One text Field and Button is     Here.

- In 4th View Controoler Table View and Map View is Taken.


2) Add Two Framework For Use of MapView :

- CoreLocation.Framework
- MapKit.Framework

3) write This Coding in Different View Controller

    Which is Given Below :


* First View Controller (For Splash Screen) :

Splash Screen.h :

#import <UIKit/UIKit.h>
#import "ViewController.h"

@interface SplashScreen : UIViewController

@property(strong,nonatomic)ViewController *viewobj;

@end

Splash Screen.m :

#import "SplashScreen.h"

@interface SplashScreen ()

@end

@implementation SplashScreen
@synthesize viewobj;

- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
    self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
    if (self) {
        // Custom initialization
    }
    return self;
}

- (void)viewDidLoad
{
    [super viewDidLoad];
    [NSTimer scheduledTimerWithTimeInterval:2.0 target:self selector:@selector(aftercomplate) userInfo:nil repeats:NO];
    
}

-(void)aftercomplate
{
    UIStoryboard *story = [UIStoryboard storyboardWithName:@"Main" bundle:nil];
    
    viewobj = [story instantiateViewControllerWithIdentifier:@"ViewController"];
    
    
    [self.navigationController pushViewController:viewobj animated:YES];

}

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

@end


* Second View Controller (For Seach) :

ViewController.h :

#import <UIKit/UIKit.h>
#import "SecViewController.h"

@interface ViewController : UIViewController

@property(strong,nonatomic)IBOutlet UITextField *txtname;
@property(strong,nonatomic)SecViewController *secobj;

-(IBAction)next:(id)sender;


@end


ViewController.m :

#import "ViewController.h"

@interface ViewController ()

@end

@implementation ViewController
@synthesize txtname,secobj;

- (void)viewDidLoad
{
    [super viewDidLoad];
    
    
    
// Do any additional setup after loading the view, typically from a nib.
}

-(IBAction)next:(id)sender
{
    NSString *stringdata = txtname.text;
    
    UIStoryboard *story = [UIStoryboard storyboardWithName:@"Main" bundle:nil];
    
    secobj = [story instantiateViewControllerWithIdentifier:@"SecViewController"];
    
    secobj.string = stringdata;
    
    [self.navigationController pushViewController:secobj animated:YES];
    
}

- (BOOL)textFieldShouldReturn:(UITextField *)textField
{
    [textField resignFirstResponder];
    return YES;
}

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

@end


* Third View Controller (For Data Show & Map) :

SecViewController.h :

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


@interface SecViewController : UIViewController<CLLocationManagerDelegate>

@property(strong,nonatomic)IBOutlet UITableView *tblobj;

@property(strong,nonatomic)IBOutlet MKMapView *mapobj;

@property(strong,nonatomic)NSMutableArray *arrobj;

@property(strong,nonatomic)NSString *string;
@property(strong,nonatomic)CLLocationManager *manager;



-(IBAction)showMap:(id)sender;

@end


SecViewController.m :

#import "SecViewController.h"
#import "Container.h"
#import "mycell.h"

#define FONT_SIZE 14.0f
#define CELL_CONTENT_WIDTH 320.0f
#define CELL_CONTENT_MARGIN 10.0f

@interface SecViewController ()
{
    int temp;
    int newrow;
}
@end

@implementation SecViewController
@synthesize arrobj,tblobj,string,mapobj,manager;

- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
    self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
    if (self) {
        // Custom initialization
    }
    return self;
}

- (void)viewDidLoad
{
    [super viewDidLoad];
    
    temp=0;
    arrobj = [[NSMutableArray alloc] init];
    
    [self getdata];
    
}

-(void)getdata
{
    NSHTTPURLResponse *responce = nil;
    
    NSString *urlstring = [NSString stringWithFormat:@"http://maps.googleapis.com/maps/api/geocode/json?address=%@",string];
    
    NSURL *urldata = [NSURL URLWithString:[urlstring stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding]];
    
    NSURLRequest *urlrequest = [[NSURLRequest alloc]initWithURL:urldata];
    
    NSData *mydata = [NSURLConnection sendSynchronousRequest:urlrequest returningResponse:&responce error:nil];
    
    NSMutableDictionary *maindic = [NSJSONSerialization JSONObjectWithData:mydata options:NSJSONReadingMutableContainers error:nil];
    
    NSMutableArray *resultarr = [maindic objectForKey:@"results"];
    
    for (int i = 0; i < resultarr.count; i++)
    {
        Container *contain = [[Container alloc] init];
        
        NSMutableDictionary *subdic = [resultarr objectAtIndex:i];
        
        NSString *stradd = [subdic objectForKey:@"formatted_address"];
        
        contain.stradd = stradd;
        
        NSMutableDictionary *geodic =[subdic objectForKey:@"geometry"];
        
        NSMutableDictionary *boundsdic = [geodic objectForKey:@"bounds"];
        
        NSMutableDictionary *northdic = [boundsdic objectForKey:@"northeast"];
        
        NSString *latstr = [northdic objectForKey:@"lat"];
        
        contain.strlat = latstr;
        
        NSString *lngstr = [northdic objectForKey:@"lng"];
        
        contain.strlng = lngstr ;
        
        [arrobj addObject:contain];
        
    }


    [tblobj reloadData];
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    int rowDesplay=0;
    
    if(arrobj.count>0)
    {
        rowDesplay=3;
    }
    return rowDesplay;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    Container *data = [arrobj objectAtIndex:0];

    
    NSString *strLat=[NSString stringWithFormat:@"%@",data.strlat];
    NSString *strLong=[NSString stringWithFormat:@"%@",data.strlng];
    


    
    mycell *cell = [tblobj dequeueReusableCellWithIdentifier:@"cell" forIndexPath:indexPath];

    if(temp==0)
    {
        
        cell.lblname.text =  data.stradd;
        NSLog(@"%@",cell.lblname.text);
    }
    else if(temp==1)
    {
        cell.lblname.text =strLat;
        NSLog(@"%@",cell.lblname.text);
    }
    else if(temp==2)
    {
        cell.lblname.text =strLong;
        NSLog(@"%@",cell.lblname.text);
    }
    temp++;
    
    [cell.lblname setLineBreakMode:NSLineBreakByCharWrapping];
    [cell.lblname setMinimumFontSize:FONT_SIZE];
    [cell.lblname setNumberOfLines:0];
    [cell.lblname setFont:[UIFont systemFontOfSize:FONT_SIZE]];
    [cell.lblname setTag:1];
    [[cell.lblname layer] setBorderWidth:2.0f];
    

    
    NSString *text = data.stradd ;
    
    CGSize constraint = CGSizeMake(CELL_CONTENT_WIDTH - (CELL_CONTENT_MARGIN * 2), 20000.0f);
    
    CGSize size = [text sizeWithFont:[UIFont systemFontOfSize:FONT_SIZE] constrainedToSize:constraint lineBreakMode:UILineBreakModeWordWrap];
    
    if (!cell.lblname)
        cell.lblname = (UILabel*)[cell viewWithTag:1];
    
  //  [cell.lblname setText:text];

    [cell.lblname setFrame:CGRectMake(CELL_CONTENT_MARGIN, CELL_CONTENT_MARGIN, CELL_CONTENT_WIDTH - (CELL_CONTENT_MARGIN * 2), MAX(size.height, 44.0f))];
    
    return cell;
    
}


- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath;
{
    Container *obj=[arrobj objectAtIndex:0];
    
    NSString *text = obj.stradd ;
    
    CGSize constraint = CGSizeMake(CELL_CONTENT_WIDTH - (CELL_CONTENT_MARGIN * 2), 20000.0f);
    
    CGSize size = [text sizeWithFont:[UIFont systemFontOfSize:FONT_SIZE] constrainedToSize:constraint lineBreakMode:UILineBreakModeWordWrap];
    
    CGFloat height = MAX(size.height, 44.0f);
    
    return height + (CELL_CONTENT_MARGIN * 2);
}


-(IBAction)showMap:(id)sender
{
    Container *shrobj=[arrobj objectAtIndex:0];
    
    
    MKCoordinateRegion region = MKCoordinateRegionMakeWithDistance(CLLocationCoordinate2DMake([shrobj.strlat floatValue],[shrobj.strlng floatValue]) , 10000, 10000);
    [mapobj setRegion:region animated:YES];
    
    MKPointAnnotation *annotetion = [[MKPointAnnotation alloc]init ];
    annotetion.coordinate = CLLocationCoordinate2DMake([shrobj.strlat floatValue], [shrobj.strlng floatValue]);
    annotetion.title= shrobj.stradd ;
    
    [mapobj addAnnotation:annotetion];
}

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

@end


* Custom Cell (Data on Cell) :

mycell.h :


#import <UIKit/UIKit.h>

@interface mycell : UITableViewCell

@property(strong,nonatomic)IBOutlet UILabel *lblname;

@end

mycell.m :

#import "mycell.h"

@implementation mycell
@synthesize lblname;

- (id)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        // Initialization code
    }
    return self;
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated
{
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

@end


* NSObject Class (For  Data Store) :

container.h :

#import <Foundation/Foundation.h>

@interface Container : NSObject

@property(strong,nonatomic)NSString *stradd;
@property(strong,nonatomic)NSString *strlat;
@property(strong,nonatomic)NSString *strlng;

@end


container.m :

#import "Container.h"

@implementation Container
@synthesize stradd,strlat,strlng;

@end