スキップしてメイン コンテンツに移動

投稿

8月, 2013の投稿を表示しています

coredatabook

/*      File: RootViewController.m  Abstract:  Abstract: The table view controller responsible for displaying the list of books, supporting additional functionality:  * Drill-down to display more information about a selected book using an instance of DetailViewController;  * Addition of new books using an instance of AddViewController;  * Deletion of existing books using UITableView's tableView:commitEditingStyle:forRowAtIndexPath: method.  The root view controller creates and configures an instance of NSFetchedResultsController to manage the collection of books.  The view controller's managed object context is supplied by the application's delegate. When the user adds a new book, the root view controller creates a new managed object context to pass to the add view controller; this ensures that any changes made in the add controller do not affect the main managed object context, and they can be committed or discarded ...

Delegate

Delegates or Properties, take your pick. PROPERTIES Class A (ViewController) wants to communicate with Class B (ViewController) Before calling Class B, do the following: In Class B, create a @property NSString* receivedValue; In Class A, #import Class B then in the method that calls B (either prepareForSegue or didSelectRowAtIndexPath or some method where you present Class B view controller, do the following: Class B *calledVC = alloc/init calledVC.receivedValue = ‘whatever value you want to pass’; then call Class B VC Done! DELEGATES Let’s say Class B wants to notify Class A that something has finished.  In Class B add this above your @interface: @protocol YourDelegateProtocol <NSObject> - (void)itemWillBePassed; @end Then in the regular Class B @interface @property (nonatomic, weak) id <YourDelegateProtocol> delegate; This means that Class B has a delegate protocol declared and anyone who wants to be its delegate needs to ...

Auto migration

NSDictionary *options = [[ NSDictionary alloc ] initWithObjectsAndKeys :[ NSNumber numberWithBool : YES ], NSMigratePersistentStoresAutomaticallyOption , [ NSNumber numberWithBool : YES ], NSInferMappingModelAutomaticallyOption , nil ];

for compatible

#if __IPHONE_OS_VERSION_MIN_REQUIRED < __IPHONE_6_0 - ( void )viewDidUnload {     // if the view has gone away, so should we set our weak pointer     _spinner = nil ;     _currentLocationActivityIndicatorView = nil ;          [ super viewDidUnload ]; } #endif

For Compatible

Loading Resources Conditionally In some cases, you need to determine the iOS version your app is currently running in so you can respond to version differences appropriately in code. For example, if different versions of an app use significantly different layouts, you can load different storyboard or XIB files for each version. You may also need to use different code paths to handle API differences, such using  barTintColor  instead of  tintColor  to tint a bar’s background. If you need to load different resources for different app versions—and you currently identify a storyboard or XIB file in your  Info.plist  file—you can use the version of the Foundation framework to determine the current system version and load the appropriate resource in application:didFinishLaunchingWithOptions: . The code below shows how to check the Foundation framework version: if ( floor ( NSFoundationVersionNumber ) <= NSFoundationVersionNumber_iOS_6_1 ) { ...

test

-( void )updateMyLocation{     CLLocation *location = [ locationManager location ];     if (!location) {         return ;     }               // Create and configure a new instance of the Event entity.     Event *event = [ NSEntityDescription insertNewObjectForEntityForName : @"Event" inManagedObjectContext : managedObjectContext ];               // Configure the new event with information from the location.     CLLocationCoordinate2D coordinate = [location coordinate ];     [event setLatitude :[ NSNumber numberWithDouble :coordinate. latitude ]];     [event setLongitude :[ NSNumber numberWithDouble :coordinate. longitude ]];     [event setDate :[ NSDate date ]];          NSUInteger randomIndex = arc4random ()% [ pinArray count ];  ...

set region

-( void )viewDidAppear:( BOOL )animated{         //new region     //regionMonitoring     if ([ CLLocationManager regionMonitoringAvailable ]){         NSNumber *eventLatitude = [ event latitude ];         NSNumber *eventLongitude = [ event longitude ];                  CLLocation *pinLocation = [[ CLLocation alloc ] initWithLatitude :[eventLatitude doubleValue ] longitude :[eventLongitude doubleValue ]];         CLLocationCoordinate2D location = pinLocation. coordinate ;         CLRegion *region = [[ CLRegion alloc ] initCircularRegionWithCenter :location radius : 10.0 identifier : @"onePin" ];         [ locationManager startMonitoringForRegion :region];     } else {         NSLog ( @"Can't report monitoring" );     } ...

Making Compass

#import "ViewController.h" @interface ViewController () @end @implementation ViewController @synthesize locationManager; @synthesize compassImage; - ( void )viewDidLoad {     [ super viewDidLoad ]; // Do any additional setup after loading the view, typically from a nib.          locationManager =[[ CLLocationManager alloc ] init ]; locationManager . desiredAccuracy = kCLLocationAccuracyBest ; locationManager . delegate = self ; if ( [ CLLocationManager locationServicesEnabled ]        &&  [ CLLocationManager headingAvailable ]) {         [ locationManager startUpdatingLocation ];         [ locationManager startUpdatingHeading ];         locationManager . headingFilter = 1 ;     } else {         NSLog ( @"Can't report heading" );     } } - ( voi...