2012-01-24 25 views
0

この記事の内容を理解しています program description Table View Controllerのページの最後には、 iOSシミュレーターでは、すべてが黒で、トップキャリアと時間があること以外は何も見ません。私のアプリはiOSシミュレータに何も表示されません

一つ、私はエラーの場所を取得していた時間[1203:FB03]アプリケーションは、アプリケーションの起動 の終わりに、ルートビューコントローラを有することが期待される、別の時間

アプリケーションデリゲートのヘッダファイル:

#import <UIKit/UIKit.h> 

UINavigationController *navigationController; 

@interface LocationsAppDelegate : UIResponder <UIApplicationDelegate> 

@property (nonatomic, retain) UINavigationController *navigationController; 
@property (strong, nonatomic) UIWindow *window; 
@property (readonly, strong, nonatomic) NSManagedObjectContext *managedObjectContext; 
@property (readonly, strong, nonatomic) NSManagedObjectModel *managedObjectModel; 
@property (readonly, strong, nonatomic) NSPersistentStoreCoordinator  *persistentStoreCoordinator; 

- (void)saveContext; 
- (NSURL *)applicationDocumentsDirectory; 



@end 

アプリケーションデリゲートの実装ファイル:

#import "LocationsAppDelegate.h" 
#import "RootViewController.h" 


@implementation LocationsAppDelegate; 
@synthesize navigationController; 

@synthesize window = _window; 
@synthesize managedObjectContext = __managedObjectContext; 
@synthesize managedObjectModel = __managedObjectModel; 
@synthesize persistentStoreCoordinator = __persistentStoreCoordinator; 

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions: (NSDictionary *)launchOptions { 

RootViewController *rootViewController = [[RootViewController alloc] 
              initWithStyle:UITableViewStylePlain]; 

NSManagedObjectContext *context = [self managedObjectContext]; 
if (!context) { 
    // Handle the error. 
} 
// Pass the managed object context to the view controller. 
rootViewController.managedObjectContext = context; 

UINavigationController *aNavigationController = [[UINavigationController alloc] 
                initWithRootViewController:rootViewController]; 
self.navigationController = aNavigationController; 

[_window addSubview:[navigationController view]]; 
[_window makeKeyAndVisible]; 


[rootViewController release]; 
[aNavigationController release]; 

return YES; 
} 


- (void)applicationWillTerminate:(UIApplication *)application 
{ 
// Saves changes in the application's managed object context before the application terminates. 
[self saveContext]; 
} 

- (void)saveContext 
{ 
NSError *error = nil; 
NSManagedObjectContext *managedObjectContext = self.managedObjectContext; 
if (managedObjectContext != nil) 
{ 
    if ([managedObjectContext hasChanges] && ![managedObjectContext save:&error]) 
    { 
     NSLog(@"Unresolved error %@, %@", error, [error userInfo]); 
     abort(); 
     } 
    } 
} 

#pragma mark - Core Data stack 

/** 
Returns the managed object context for the application. 
If the context doesn't already exist, it is created and bound to the persistent store coordinator for the application. 
*/ 
- (NSManagedObjectContext *)managedObjectContext 
{ 
if (__managedObjectContext != nil) 
{ 
    return __managedObjectContext; 
} 

NSPersistentStoreCoordinator *coordinator = [self persistentStoreCoordinator]; 
if (coordinator != nil) 
{ 
    __managedObjectContext = [[NSManagedObjectContext alloc] init]; 
    [__managedObjectContext setPersistentStoreCoordinator:coordinator]; 
} 
return __managedObjectContext; 
} 

/** 
Returns the managed object model for the application. 
If the model doesn't already exist, it is created from the application's model. 
*/ 
- (NSManagedObjectModel *)managedObjectModel 
{ 
if (__managedObjectModel != nil) 
{ 
    return __managedObjectModel; 
} 
NSURL *modelURL = [[NSBundle mainBundle] URLForResource:@"Locations"  withExtension:@"momd"]; 
__managedObjectModel = [[NSManagedObjectModel alloc] initWithContentsOfURL:modelURL]; 
return __managedObjectModel; 
} 

/** 
Returns the persistent store coordinator for the application. 
If the coordinator doesn't already exist, it is created and the application's store added  to it. 
*/ 
- (NSPersistentStoreCoordinator *)persistentStoreCoordinator 
{ 
if (__persistentStoreCoordinator != nil) 
{ 
    return __persistentStoreCoordinator; 
} 

NSURL *storeURL = [[self applicationDocumentsDirectory] URLByAppendingPathComponent:@"Locations.sqlite"]; 

NSError *error = nil; 
__persistentStoreCoordinator = [[NSPersistentStoreCoordinator alloc] initWithManagedObjectModel:[self managedObjectModel]]; 
if (![__persistentStoreCoordinator addPersistentStoreWithType:NSSQLiteStoreType configuration:nil URL:storeURL options:nil error:&error]) 
{ 
      NSLog(@"Unresolved error %@, %@", error, [error userInfo]); 
    abort(); 
}  

return __persistentStoreCoordinator; 
} 

#pragma mark - Application's Documents directory 

/** 
Returns the URL to the application's Documents directory. 
*/ 
- (NSURL *)applicationDocumentsDirectory 
{ 
return [[[NSFileManager defaultManager] URLsForDirectory:NSDocumentDirectory inDomains:NSUserDomainMask] lastObject]; 
} 

@end 

ビューコントローラヘッダーファイル:

#import <CoreLocation/CoreLocation.h> 

@interface RootViewController : UITableViewController <CLLocationManagerDelegate> { 

NSMutableArray *eventsArray; 
NSManagedObjectContext *managedObjectContext; 

CLLocationManager *locationManager; 
UIBarButtonItem *addButton; 
} 

@property (nonatomic, retain) NSMutableArray *eventsArray; 
@property (nonatomic, retain) NSManagedObjectContext *managedObjectContext; 

@property (nonatomic, retain) CLLocationManager *locationManager; 
@property (nonatomic, retain) UIBarButtonItem *addButton; 


@end 

ビューコントローラの実装ファイル

// 
// RootViewController.m 
// Locations 


#import "RootViewController.h" 

@implementation RootViewController 

@synthesize eventsArray; 
@synthesize managedObjectContext; 
@synthesize addButton; 
@synthesize locationManager; 

- (CLLocationManager *)locationManager { 

if (locationManager != nil) { 
    return locationManager; 
} 

locationManager = [[CLLocationManager alloc] init]; 
locationManager.desiredAccuracy = kCLLocationAccuracyNearestTenMeters; 
locationManager.delegate = self; 

return locationManager; 
} 

- (void)locationManager:(CLLocationManager *)manager 
didUpdateToLocation:(CLLocation *)newLocation 
     fromLocation:(CLLocation *)oldLocation { 
addButton.enabled = YES; 
} 

- (void)locationManager:(CLLocationManager *)manager 
    didFailWithError:(NSError *)error { 
addButton.enabled = NO; 
} 

#pragma mark - View lifecycle 

- (void)viewDidLoad { 


[super viewDidLoad]; 
// Set the title. 
self.title = @"Locations"; 

// Set up the buttons. 
self.navigationItem.leftBarButtonItem = self.editButtonItem; 

addButton = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemAdd 
                  target:self  action:@selector(addEvent)]; 
addButton.enabled = NO; 
self.navigationItem.rightBarButtonItem = addButton; 

// Start the location manager. 
[[self locationManager] startUpdatingLocation]; 
} 

- (void)viewDidUnload { 
self.eventsArray = nil; 
self.locationManager = nil; 
self.addButton = nil; 
} 


- (void)dealloc { 
[managedObjectContext release]; 
[eventsArray release]; 
[locationManager release]; 
[addButton release]; 
[super dealloc]; 
} 



#pragma mark - Table view data source 

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView 
{ 
#warning Potentially incomplete method implementation. 
// Return the number of sections. 
return 0; 
} 

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section 
{ 
#warning Incomplete method implementation. 
// Return the number of rows in the section. 
return 0; 
} 

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath 
{ 
static NSString *CellIdentifier = @"Cell"; 

UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier]; 
if (cell == nil) { 
    cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier]; 
} 

// Configure the cell... 

return cell; 
} 

    #pragma mark - Table view delegate 

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath 
{ 
// Navigation logic may go here. Create and push another view controller. 
/* 
<#DetailViewController#> *detailViewController = [[<#DetailViewController#> alloc] initWithNibName:@"<#Nib name#>" bundle:nil]; 
// ... 
// Pass the selected object to the new view controller. 
[self.navigationController pushViewController:detailViewController animated:YES]; 
*/ 
} 

@end 

は、誰かが私を助けてくださいことはできますか?

+0

アプリケーションデリゲートのapplicationDidFinishLaunchingメソッドのコードを投稿できますか? – Vin

+0

コードを質問に編集してください。コメントでコードの書式設定ができないため、読みにくいです。 –

+0

私はここにいくつかのコードを入れましたが、それはリンクプログラムのディスクの中のものと同じです –

答えて

1

私は船長のように感じていますが、あなたはwindow.rootViewControllerを設定するのを忘れました。

+0

どこに設定する必要がありますか? –

+0

'アプリケーション:didFinishLaunchingWithOptions:'メソッドは 'self.window.rootViewController = self.navigationController;'を実行します。 –

+0

私はそれを変更しましたが、何も起こりません。それはまだ黒で私はiOSシミュレータのオペアンプでキャリアの日付のバッテリーを表示するすべてを表示します。しかし、私はXcode 4.2を使用していますこれは多分空のアプリケーションとXcode 4.1にあるウィンドウベースのアプリケーションの違いとは何ですか?私が変えたもう一つの事は、ARCをオフにしたことです。 –

関連する問題