2012-05-09 12 views
0

私は自分のタブバーアプリケーションにCoreDataを使い、CoreData機能が動作しています(つまり、コンソールから情報を出力できます)。問題は、私のタブバーが機能していないことです。私は私のアプリを実行すると、それは次のようになります。アイテムが表示されていないタブバー

enter image description here

タブバー自体が現れているが、いずれかの項目がないと、それは、テーブルビューが表示されていないかのように見えます。

AppDelegate.h

#import <UIKit/UIKit.h> 

#import "JobsViewController.h" 
#import "Job.h" 
#import "Shift.h" 

@interface AppDelegate : UIResponder <UIApplicationDelegate> 

@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 

AppDelegate.m

#import "AppDelegate.h" 

@implementation AppDelegate 

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

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions 
{  
    NSManagedObjectContext *context = [self managedObjectContext]; 
    Job *job = [NSEntityDescription insertNewObjectForEntityForName:@"Job" inManagedObjectContext:context]; 
    job.employer = @"Calder Centre"; 
    job.jobTitle = @"Addictions Counsellor"; 
    job.regularRate = 25.9f; 
    job.overtimeRate = 30.5f; 
    job.deduction1 = 0.1f; 
    job.deduction2 = 0.2f; 
    job.deduction3 = 0.3f; 
    job.deduction4 = 0.4f; 
    job.deduction1Name = @"CPP"; 
    job.deduction2Name = @"IT"; 
    job.deduction3Name = @"Union Dues"; 
    job.deduction4Name = @"Other"; 

    Shift *shift = [NSEntityDescription insertNewObjectForEntityForName:@"Shift" inManagedObjectContext:context]; 
    shift.startDate = [NSDate date]; 
    shift.endDate = [NSDate date]; 

    NSError *error; 
    if (![context save:&error]) { 
     NSLog(@"Whoops, couldn't save: %@", [error localizedDescription]); 
    } 

    // Test listing all FailedBankInfos from the store 
    NSFetchRequest *jobFetchRequest = [[NSFetchRequest alloc] init]; 
    NSEntityDescription *jobEntity = [NSEntityDescription entityForName:@"Job" inManagedObjectContext:context]; 
    [jobFetchRequest setEntity:jobEntity]; 
    NSArray *fetchedJobs = [context executeFetchRequest:jobFetchRequest error:&error]; 
    for (Job *job in fetchedJobs) { 
     NSLog(@"Employer: %@", job.employer); 
     NSLog(@"Title: %@", job.jobTitle); 
    } 

    NSFetchRequest *shiftFetchRequest = [[NSFetchRequest alloc] init]; 
    NSEntityDescription *shiftEntity = [NSEntityDescription entityForName:@"Shift" inManagedObjectContext:context]; 
    [shiftFetchRequest setEntity:shiftEntity]; 
    NSArray *fetchedShifts = [context executeFetchRequest:shiftFetchRequest error:&error]; 
    for (Shift *shift in fetchedShifts) { 
     NSLog(@"Start Date: %@", shift.startDate); 
     NSLog(@"End Date: %@", shift.endDate); 
    } 

    self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]]; 
    // Override point for customization after application launch. 

    UITabBarController *tabBarController = [[UITabBarController alloc]init]; 
    self.window.rootViewController = tabBarController; 

    self.window.backgroundColor = [UIColor whiteColor]; 
    [self.window makeKeyAndVisible]; 

    return YES; 
} 

ここにある:私のAppDelegateのコードがされる。ここ

enter image description here

:私の絵コンテは、このようになりますビューコントローラ:

JobsViewController.h

#import <UIKit/UIKit.h> 
#import "Job.h" 
#import "Shift.h" 

@interface JobsViewController : UITableViewController 

@property (nonatomic, strong) NSManagedObjectContext* managedObjectContext; 
@property (nonatomic, strong) NSArray *listOfJobs; 

@end 

JobsViewController.m

#import "JobsViewController.h" 

@interface JobsViewController() 

@end 

@implementation JobsViewController 

@synthesize managedObjectContext, listOfJobs; 

- (void)viewDidLoad 
{ 
    [super viewDidLoad]; 

    // Uncomment the following line to display an Edit button in the navigation bar for this view controller. 
    self.navigationItem.rightBarButtonItem = self.editButtonItem; 

    NSFetchRequest *fetchRequest = [[NSFetchRequest alloc] init]; 
    NSEntityDescription *entity = [NSEntityDescription 
            entityForName:@"Job" inManagedObjectContext:managedObjectContext]; 
    [fetchRequest setEntity:entity]; 
    NSError *error; 
    self.listOfJobs = [managedObjectContext executeFetchRequest:fetchRequest error:&error]; 
    self.title = @"Jobs"; 
} 

#pragma mark - Table view data source 

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView 
{ 
    // Return the number of sections. 
    return 1; 
} 

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section 
{ 
    // Return the number of rows in the section. 
    return [listOfJobs count]; 
} 

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath 
{ 
    static NSString *CellIdentifier = @"job"; 
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier]; 

    if (!cell) { 
     cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:CellIdentifier]; 
    } 

    // Configure the cell... 
    Job *job = [listOfJobs objectAtIndex:indexPath.row]; 
    cell.textLabel.text = job.jobTitle; 
    cell.detailTextLabel.text = job.employer; 

    return cell; 
} 
+0

無関係なコードがたくさんあったので、私はあなたの質問からかなり多くを削除しました。希望はOKです。 – jrturton

+0

さて、確かに。私はそれをしていたはずです。 – Barks

答えて

1

これは、コアデータとは何の関係もありません。

ストーリーボード以外のプロジェクトのアプリケーションデリゲートテンプレートのコードを使用していますが、ストーリーボードを使用しています。 didFinishLaunchingメソッドのコードは、新しいウィンドウと空のタブバーコントローラーを作成して、ストーリーボードから何かをオーバーライドします。

return YES;を除いて、self.window =の後にすべてを取り除きます。これはxibベースのアプリケーションで使用されるコードであり、ストーリーボードがある場合は不要です。

+0

Lol。私はそれが何かシンプルになることを知っていたが、それはそれが単純なものになるとは思わなかった。ありがとう:) – Barks

関連する問題