gpt4 book ai didi

objective-c - Xcode Interface Builder 不显示 App Delegate 对象

转载 作者:可可西里 更新时间:2023-11-01 03:37:20 30 4
gpt4 key购买 nike

我正在使用“IOS 编程:Big Nerd Ranch 指南(第 2 版)”自学 Objective-C 和 iOS 编程,我遇到了一个问题,教程要求我创建与 App Delegate 对象的连接,但是这个对象没有出现在我的 Interface builder 的对象列表中。我很确定它要么是错字,要么是版本不同,因为这本书略微落后于我的 Xcode (4.2) 版本。我已经包含了代码。我相当确定 MOCAppDelegate 对象应该出现在 IB 中,但我还不够熟悉,无法知道我需要更改哪些代码才能实现。具体问题:如何调整下面的代码,以便我在IB 中的对象列表,以便我可以按照教程图形中的说明执行连接?

注意:我研究并发现了这个:Having trouble hooking up instance variables to AppDelegate但是这个解决方案对我不起作用(或者我没有正确实现它)

ScreenShot头文件

#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 中,然后按照您所获得的说明将其放入对象部分。然后选择它并在身份检查器(在右侧,显示“自定义类”的地方)中将其类型更改为“MOCAppDelegate”(或您喜欢的任何类)。

关于objective-c - Xcode Interface Builder 不显示 App Delegate 对象,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8796977/

30 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com