Xcode界面生成器不显示应用程序委托对象
我正在教自己Objective-C和iOS编程与“IOS编程:大书呆子牧场指南(第二版),我遇到了一个问题,其中教程要我创build连接到应用程序委托对象,但此对象不出现在界面生成器中的对象列表中,对于我来说,我相当确定它是一个错字还是一个不同的版本,因为这本书稍微落后于我的Xcode版本(4.2),我已经包含了代码。 MOCAppDelegate对象是在IB中应该显示的内容,但是我还不够熟悉需要做什么代码更改。具体问题:如何调整下面的代码以便在对象列表中获取对象在IB中,以便我可以按照教程图中的说明执行连接。
注意:我研究并发现了这个: 将实例variables连接到AppDelegate时遇到困难,但是这个解决scheme对我来说并不适用(或者我没有正确实现)
头文件
#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
实施文件
#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
将NSObject的一个实例拖放到.xib文件中,并将其放在Objects部分中,就像您获得的说明一样。 然后select它并在身份检查器(在右侧,它表示“自定义类”)中将其types更改为“MOCAppDelegate”(或任何您喜欢的类)。
您应该从对象库中拖动一个“NSObject”到您要连接的视图控制器下方的黑色条上的故事板。 然后,点击NSObject并在身份检查器中将类更改为AppDelegate。 然后,您可以创build到AppDelegate的连接。
MOCAppDelegate = AppDelegate
代码是在您为项目命名时为您生成的。 UIApplication对象的委托通常根据项目的名称命名有所不同。
(毫无疑问,任何印刷书籍都使用旧的Xcode。)
selectFiles Owner
和Identity Inspector(command-alt-2)来确认文件的所有者是应用程序委托的占位符。
- 在Interface Builder中使用资产目录上的图像
- iOS 8启动图像文件 – 导航栏和状态栏
- XcodeのRun Scriptフェーズを无效にしてビルド时间を短缩する(スクリプト付き)
- 将.xib中的对象连接到现有的IBAction
- 更改每个实例的UITableViewCell宽度约束的常量值
- 构build设置:我应该在构build设置中做什么更改,以便在发布应用程序时,它将在App Store上显示为仅英语的语言?
- 如何在两个开发人员的团队中使用分发证书
- 如何创buildUISearchController,因为UISearchDisplayController在iOS 8中已被弃用?
- 在目标c中导入标题