Xcode Interface Builder Do not show application delegation object

I teach myself Objective-C and iOS programming using the "IOS Programming: The Big Nerd Ranch guide (2nd Edition)), and I had a problem when the tutorial wants me to create connections to the application delegation object, but this object is not appears in the Objects list in the interface builder for me. I’m sure this is either a typo or maybe a different version, because the book is slightly behind my version of Xcode (4.2). I have included the code. that the MOCAppDelegate object is something that should appear in IB, but I'm not yet familiar enough to know what code changes I need to do . S specific question: how do I configure the code below to get the object in the list of objects in IB, so that I can perform the connection as shown in the graphic tutorial?

Note. I researched and found this: Failed to connect instance variables to AppDelegate , but this solution did not work for me (or I did not implement it correctly)

Screen shot Header file

#import <UIKit/UIKit.h> #import <CoreLocation/CoreLocation.h> #import <MapKit/MapKit.h> @interface MOCAppDelegate : UIResponder <UIApplicationDelegate, CLLocationManagerDelegate> { CLLocationManager *locationManager; IBOutlet MKMapView *worldView; IBOutlet UIActivityIndicatorView *activityIndicator; IBOutlet UITextField *locationTitleField; } @property (strong, nonatomic) IBOutlet UIWindow *window; @end 

Implementation file

 #import "MOCAppDelegate.h" @implementation MOCAppDelegate @synthesize window = _window; - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions { //Create location manager object locationManager = [[CLLocationManager alloc] init]; [locationManager setDelegate:self]; //We want all results from the location manager [locationManager setDistanceFilter:kCLDistanceFilterNone]; //And we want it to be as accurate as possible //regardless of how much time/power it takes [locationManager setDesiredAccuracy:kCLLocationAccuracyBest]; //Tell our location manager to start looking for it location immediately [locationManager startUpdatingLocation]; //We also want to know our heading if (locationManager.headingAvailable == true) { [locationManager startUpdatingHeading]; } self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]]; // Override point for customization after application launch. self.window.backgroundColor = [UIColor darkGrayColor]; [self.window makeKeyAndVisible]; return YES; } - (void)locationManager:(CLLocationManager *)manager didUpdateToLocation:(CLLocation *)newLocation fromLocation:(CLLocation *)oldLocation { NSLog(@"%@", newLocation); } - (void)locationManager:(CLLocationManager *)manager didUpdateHeading:(CLHeading *)newHeading { NSLog(@"%@", newHeading); } - (void)locationManager:(CLLocationManager *)manager didFailWithError:(NSError *)error { NSLog(@"Could not find location: %@", error); } - (void)dealloc { if( [locationManager delegate] == self) [locationManager setDelegate:nil]; } - (void)applicationWillResignActive:(UIApplication *)application { /* Sent when the application is about to move from active to inactive state. This can occur for certain types of temporary interruptions (such as an incoming phone call or SMS message) or when the user quits the application and it begins the transition to the background state. Use this method to pause ongoing tasks, disable timers, and throttle down OpenGL ES frame rates. Games should use this method to pause the game. */ } - (void)applicationDidEnterBackground:(UIApplication *)application { /* Use this method to release shared resources, save user data, invalidate timers, and store enough application state information to restore your application to its current state in case it is terminated later. If your application supports background execution, this method is called instead of applicationWillTerminate: when the user quits. */ } - (void)applicationWillEnterForeground:(UIApplication *)application { /* Called as part of the transition from the background to the inactive state; here you can undo many of the changes made on entering the background. */ } - (void)applicationDidBecomeActive:(UIApplication *)application { /* Restart any tasks that were paused (or not yet started) while the application was inactive. If the application was previously in the background, optionally refresh the user interface. */ } - (void)applicationWillTerminate:(UIApplication *)application { /* Called when the application is about to terminate. Save data if appropriate. See also applicationDidEnterBackground:. */ } @end 
+6
source share
3 answers

Drag the NSObject instance into your .xib and drop it in the Objects section just like in the instructions you have. Then select it and change its type in the Identity Inspector (on the right side where it says “Custom Class”) to “MOCAppDelegate” (or any other class that you like).

+14
source

You have to drag "NSObject" from the object library onto your storyboard in the black bar under the view controller that you want to connect. Then click NSObject and in the Identity Inspector change the class to AppDelegate. Then you can create a connection to AppDelegate.

+3
source

MOCAppDelegate = AppDelegate

The code was created for you when you named the project. The UIApplication object delegate is usually called slightly different depending on the name of the project.

(There is no doubt that the old Xcode was used in any book in print.)

Select Files Owner , and Identity Inspector (command-alt-2) to confirm the owner of the file is the owner of the space for the application delegate.

0
source

Source: https://habr.com/ru/post/905578/


All Articles