Thursday, October 31, 2013

Using Reachability in iOS


Add the SystemConfiguration framework


#import "Reachability.h"

-(BOOL)reachable {
    NSString *hostName = @"google.com";
    Reachability *r = [Reachability reachabilityWithHostName:hostName];
    NetworkStatus internetStatus = [r currentReachabilityStatus];
    if(internetStatus == NotReachable) {
        return NO;
    }
    return YES;
}


if ([self reachable]) {
    NSLog(@"Reachable");
}
else {
    NSLog(@"Not Reachable");
}

Creating PopOverView for iPad

-(void)showPickerView : (NSString *)aScore{
  
  UIViewController* popoverContentViewController = [[UIViewController alloc] init];
  
  UIView *popoverView = [[UIView alloc] init];   //view
  popoverView.backgroundColor = [UIColor whiteColor];
  
  
  // Load tempView
  
  UIView *tempView   = nil;
  NSArray *arr   = nil;
  CGRect frame   = CGRectZero;
  CGRect popOverFrame = CGRectZero;
  
  if([aScore isEqualToString:@"performanceScore"]){
arr = [[NSBundle mainBundle] loadNibNamed:@"PerformanceScoreView" owner:self options:nil];
tempView = [arr objectAtIndex:0];
popOverFrame = CGRectMake(0, 0, 200, 150);

frame = self.performanceScoreTitleLbl.frame;
  } else {
arr = [[NSBundle mainBundle] loadNibNamed:@"BreeamScoreView" owner:self options:nil];
tempView = [arr objectAtIndex:0];
popOverFrame = CGRectMake(0, 0, 220, 380);
frame = self.breeamScoreTitleLbl.frame;
  }
  
  [popoverView addSubview:tempView];
  popoverContentViewController.view = popoverView;
  
  
  popoverController = [[UIPopoverController alloc] initWithContentViewController:popoverContentViewController];
  [popoverController setPopoverContentSize:CGSizeMake(popOverFrame.size.width, popOverFrame.size.height) animated:NO];
  [popoverController presentPopoverFromRect:frame inView:self permittedArrowDirections:UIPopoverArrowDirectionLeft animated:YES];

}


Reading from JSON File in ObjectiveC

NSString *fileName = @"property3.json";
NSString *filePath = [[[NSBundle mainBundle] bundlePath] stringByAppendingPathComponent:fileName];
NSString *jsonString = [NSString stringWithContentsOfFile:filePath encoding:NSUTF8StringEncoding error:nil];
NSData *jsonData = [jsonString dataUsingEncoding:NSUTF8StringEncoding];
NSError *jsonError = nil;
NSDictionary *propertyDict = [NSJSONSerialization JSONObjectWithData:jsonData options:kNilOptions error:&jsonError];
if(jsonError) {
  NSLog(@"jsonError : %@", [jsonError localizedDescription]);
} else {
  //NSLog(@"propertyDict : %@", propertyDict);

}

Thursday, October 24, 2013

iOS 6.0 to iOS 7.0 full screen transition



self.edgesForExtendedLayout =  UIRectEdgeTop | UIRectEdgeLeft | UIRectEdgeBottom | UIRectEdgeRight;

Unwind Segue Programmatically



#pragma mark - Trigger for unwind seque programmatically
- (IBAction) done: (id)sender
{
        SEL theUnwindSelector = @selector(goToRoot:);
        NSString *unwindSegueIdentifier = @"unwindToRootSeque";
     
        UINavigationController *nc = [self navigationController];
        // Find the view controller that has this unwindAction selector (may not be one in the nav stack)
        UIViewController *viewControllerToCallUnwindSelectorOn = [nc viewControllerForUnwindSegueAction: theUnwindSelector
                                                                                     fromViewController: self
                                                                                             withSender: sender];
        // None found, then do nothing.
        if (viewControllerToCallUnwindSelectorOn == nil) {
            NSLog(@"No controller found to unwind too");
            return;
        }
     
        // Can the controller that we found perform the unwind segue.  (This is decided by that controllers implementation of canPerformSeque: method
        BOOL cps = [viewControllerToCallUnwindSelectorOn canPerformUnwindSegueAction: theUnwindSelector
                                                                  fromViewController: self
                                                                          withSender: sender];
        // If we have permision to perform the seque on the controller where the unwindAction is implmented
        // then get the segue object and perform it.
        if (cps) {
             
            UIStoryboardSegue *unwindSegue = [nc segueForUnwindingToViewController: viewControllerToCallUnwindSelectorOn fromViewController: self identifier: unwindSegueIdentifier];
 
            [viewControllerToCallUnwindSelectorOn prepareForSegue: unwindSegue sender: self];
             
            [unwindSegue perform];
        }  
}