Mi sto insegnando Programmazione Objective-C e iOS con "Programmazione IOS: la guida di Big Nerd Ranch (2a edizione) e ho riscontrato un problema in cui il tutorial mi chiede di creare connessioni a un oggetto Delega app, ma questo oggetto non è presente nell'elenco Oggetti in Interface builder per me. Sono abbastanza sicuro che sia un errore di battitura o forse una versione diversa in quanto il libro è leggermente indietro rispetto alla mia versione di Xcode (4.2). ho incluso il codice. Sono abbastanza certo che l'oggetto MOCAppDelegate è ciò che dovrebbe essere mostrato in IB, ma non sono ancora abbastanza familiare da sapere quali modifiche al codice devo fare per realizzarlo. Domanda specifica: Come aggiusto il codice di seguito in modo che ottenga un oggetto nell'elenco Oggetti in IB in modo da poter eseguire le connessioni come indicato nel grafico tutorial?Xcode Interface Builder Non mostra oggetto Delega app
Nota: ho ricercato e trovato questo: Having trouble hooking up instance variables to AppDelegate ma questa soluzione non ha funzionato per me (o non mi ha attuato in modo corretto)
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
Attuazione 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
Grazie! Questo passaggio fondamentale è stato saltato nella maggior parte delle guide. – pretzels1337
Anche io sono bravo. Ci sono alcuni documenti là fuori che devono essere aggiornati. Complimenti allo Stack Overflow per mostrare domande simliar mentre scrivi il tuo! – McUsr