2012-01-10 17 views
6

私はObjective-CとiOSプログラミングを「IOSプログラミング:The Big Nerd Ranchガイド(第2版)」で教えているので、チュートリアルで接続を作成したいという問題が発生しましたApp Delegateオブジェクトには、このオブジェクトは私のためのInterface builderのObjectsリストには表示されません。私は、その本のバージョンがXcode(4.2)の少し後ろにあるかのように、タイプミスかバージョンが異なると確信しています。私は、MOCAppDelegateオブジェクトがIBに表示されるべきものであることはかなり確信していますが、私はそれを実現するために必要なコードの変更を知るにはまだよく分かりません。以下のようにして、チュートリアルのグラフィックの指示どおりに接続を実行できるように、IBのオブジェクトリストにオブジェクトが表示されます。Xcode Interface Builderアプリケーションデリゲートオブジェクトが表示されない

注:私は研究し、この発見: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 

答えて

14

NSObjectのインスタンスを.xibにドラッグして、オブジェクトのセクションにドロップします。次に、それを選択し、アイデンティティ・インスペクタ(右側の「カスタム・クラス」と表示されます)のタイプを「MOCAppDelegate」(または好きなクラス)に変更します。

+3

ありがとう!この基本的なステップは、ほとんどのガイドでは省略されています。 – pretzels1337

+1

私はあまりにもgreatefulです。そこにはsomドキュメントが更新される必要があります。あなたがあなたのタイプを入力している間にsimliarの質問を表示するためのオーバーフローへの優しさ! – McUsr

0

MOCAppDelegate = AppDelegate

cプロジェクトに名前を付けたときにodeが生成されました。 UIApplicationオブジェクトのデリゲートは、通常、プロジェクトの名前によって若干異なる名前が付けられます。ファイルの所有者を確認する

(印刷のいずれかの本は古いのXcodeを使用していたことは疑いがあります。)

選択Files Ownerとアイデンティティインスペクター(コマンド-ALT-2)は、アプリデリゲートのプレースホルダーです。

+0

私はこの変更を行ったが、IBは更新しなかった。それを "リフレッシュ"するために何かしなければならないことはありますか? – Ketema

+0

「ファイルの所有者」プレースホルダを選択すると、アイデンティティ・インスペクタはそのクラスを空白として表示し、アイデンティティ・ダイアログにはラベル:ファイル所有者、ObjectID:-1、ロック:継承 - (なし)、注:チェック・ボックス。私はクラスをMOCAppDelegateに変更しようとしましたが、プレースホルダの下のオブジェクトリストにデリゲートを表すオブジェクトを取得しません。 – Ketema

3

オブジェクトライブラリから "NSObject"を接続するビューコントローラの下の黒いバーのストーリーボードにドラッグする必要があります。次に、NSObjectをクリックし、IDインスペクタでクラスをAppDelegateに変更します。その後、AppDelegateへの接続を作成することができます。

関連する問題