Monday, February 17, 2014

Push and Pop VC based on Sting Selection




Push to View Controller  based on String 

A ===>VC

.M File

-(void) push
{

VCName *vcobj=[[VCName alloc]initWithNibName:@"VCName" bundle:nil];
 [vcobj setPageString:@"SelectVC"];
    [self.navigationController vcobj animated:YES];


// Example
ArriveTicketViewController *arrivelView=[[ArriveTicketViewController alloc]initWithNibName:@"ArriveTicketViewController" bundle:nil];
 [arrivelView setPageString:@"SelectVC"];
    [self.navigationController pushViewController:arrivelView animated:YES];

}



B ====> VC

.h File

{
NSString *pageString;

}

@property(nonatomic,strong) NSString *pageString;

.M File


@synthesize pageString;


if([self.pageString isEqualToString:@“SelectVC”])
   {
     // perform action
     
   }



Poping the ViewController


-(void)PopToVC
{
    for (UIViewController *viewcontroller in [self.navigationController viewControllers])
    {
        if ([viewcontroller isKindOfClass:[VCName class]])
        {
            VCNameobj =(VCName *)viewcontroller;
            VCNameobj.pageString=@"SelectVC";
            [self.navigationController popToViewController:viewcontroller animated:YES];
        }
    }

}

Sunday, February 16, 2014

Getting Current Location



.h file


    BOOL didFindLocation;

.m file

- (void)viewDidLoad
  [self startFindLocation];

-(void)startFindLocation
{
    self.didFindLocation=NO;
    locationManager = [[CLLocationManager alloc] init];
    locationManager.delegate = self;
    locationManager.desiredAccuracy = kCLLocationAccuracyBest;
    [locationManager startUpdatingLocation];

}


#pragma mark Map Current Location=========================


- (void)locationManager:(CLLocationManager *)manager didFailWithError:(NSError *)error
{
//    UIAlertView *errorAlert = [[UIAlertView alloc]
//                               initWithTitle:@"Error" message:@"Failed to Get Your Location" delegate:nil cancelButtonTitle:@"OK" otherButtonTitles:nil];
//    [errorAlert show];
}

- (void)locationManager:(CLLocationManager *)manager didUpdateToLocation:(CLLocation *)newLocation fromLocation:(CLLocation *)oldLocation
{
    
    CLLocation *currentLocation = newLocation;
    
    if (!self.didFindLocation)
    {
        self.didFindLocation = YES;
        [locationManager stopUpdatingLocation];

       self.longitude = [NSString stringWithFormat:@"%.8f", currentLocation.coordinate.longitude];
        self.latitude = [NSString stringWithFormat:@"%.8f", currentLocation.coordinate.latitude];

       NSLog(@"strLongitude===%@",self.longitude);
        
        NSLog(@"strLatitude===%@",self.latitude);


    }
    
   

}

NULL Checking For Webservices



#pragma mark ======== Null Checking for web services ===============

+(id)checkForNull:(id)value
{
    NSString *valueString = [NSString stringWithFormat:@"%@",value];
    
    id objectString = @"";
    
    if (![valueString isEqualToString:@"(null)"] && ![valueString isEqualToString:@"<null>"] && valueString.length != 0)
        return value;
    
    return objectString;

}



EX


 [localTrendsData setPhone_number:[self checkForNull:[currentLocalTrends valueForKey:@"phone_number"]]];
            
            [localTrendsData setUser_id:[self checkForNull:[currentLocalTrends valueForKey:@"user_id"]]];
            
            [localTrendsData setCategoryNameArray:[self checkForNull:[currentLocalTrends valueForKey:@"categories"]]];