2013-10-14 2 views
0

Я пытаюсь создать приложение, использующее просмотр с вкладками. Я не могу понять, как правильно назначить мой корневой контроллер, и xcode продолжает давать мне эту ошибку.ошибки в корневом контроллере

«2013-10-13 18: 51: 56.688 FoxSays [23795: a0b] Ожидается, что окна приложений будут иметь корневой режим контроллер в конце запуска приложения "

приложение запускает, но просто передает белый экран. Мне сказали, что это потому, что xcode не может определить, какой экран он должен отображать.

Я отправлю код, который у меня есть, в надежде, что кто-то может мне помочь. там есть некоторые случайные незавершенные вещи, но прямо сейчас я просто пытаюсь показать его, прежде чем идти дальше. Заранее спасибо.

// 
// FSAppDelegate.h 
// FoxSays 
// 
// Created by Scott Pfeiffer on 10/1/13. 
// Copyright (c) 2013 Bradley. All rights reserved. 
// 

#import <UIKit/UIKit.h> 
#import <Parse/Parse.h> 

@interface FSAppDelegate : UIResponder <UIApplicationDelegate> 

@property (strong, nonatomic) UIWindow *window; 

@end 

.

// 
// FSAppDelegate.m 
// FoxSays 
// 
// Created by Scott Pfeiffer on 10/1/13. 
// Copyright (c) 2013 Bradley. All rights reserved. 
// 

#import <Parse/Parse.h> 
#import "FSAppDelegate.h" 

@implementation FSAppDelegate 



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

    self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]]; 
    // Override point for customization after application launch. 
    self.window.backgroundColor = [UIColor whiteColor]; 
    [self.window makeKeyAndVisible]; 
    return YES; 

    //parse key 
    [Parse setApplicationId:@"cG4arrkdJdTSHMwczQ4EQ7Lhj1qWjnoGDjGxtVZg" 
        clientKey:@"xVgThu6c55mm6e0TOmBLc4u5T4KCV4yqReYkekUP"]; 

    //parse analytics 
    [PFAnalytics trackAppOpenedWithLaunchOptions:launchOptions]; 
} 

- (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 

.

// 
// FSHomeViewController.h 
// FoxSays 
// 
// Created by Scott Pfeiffer on 10/1/13. 
// Copyright (c) 2013 Bradley. All rights reserved. 
// 

#import <AVFoundation/AVAudioPlayer.h> 
#import <UIKit/UIKit.h> 
#import <AudioToolbox/AudioToolbox.h> 
#import "FSItemStore.h" 
#import "FSItem.h" 

@interface FSHomeViewController : UITabBarController 

- (IBAction)playAudio:(id)sender; 

@end 

.

// 
    // FSHomeViewController.m 
    // FoxSays 
    // 
    // Created by Scott Pfeiffer on 10/1/13. 
    // Copyright (c) 2013 Bradley. All rights reserved. 
    // 

    #import "FSHomeViewController.h" 
    #import "FSItem.h" 
    #import "FSItemStore.h" 

    @interface FSHomeViewController() 

    @property (weak, nonatomic) IBOutlet UIButton *playAudio; 

    @end 

    @implementation FSHomeViewController 

    - (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil 
    { 
     self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil]; 
     if (self) { 
      // Custom initialization 
     } 
     return self; 
    } 



    - (void)viewDidLoad 
    { 
     [super viewDidLoad]; 
     // Do any additional setup after loading the view. 
    } 

    - (void)didReceiveMemoryWarning 
    { 
     [super didReceiveMemoryWarning]; 
     // Dispose of any resources that can be recreated. 
    } 

    - (IBAction)playAudio:(id)sender { 
     AVAudioPlayer *audioPlayer; 
     NSString *audioPath = [[NSBundle mainBundle] pathForResource:@"Woof" ofType:@"mp3"]; 
     NSURL *audioURL = [NSURL fileURLWithPath:audioPath]; 
     NSError *audioError = [[NSError alloc] init]; 
     audioPlayer = [[AVAudioPlayer alloc] initWithContentsOfURL:audioURL error:&audioError]; 

     if (!audioError) { 
      [audioPlayer play]; 
      NSLog(@"Woof!"); 
     } 
     else { 
      NSLog(@"Error!"); 
     } 
    } 



    @end 

.

// 
// FSAnimalsViewController.h 
// FoxSays 
// 
// Created by Scott Pfeiffer on 10/1/13. 
// Copyright (c) 2013 Bradley. All rights reserved. 
// 

#import <AVFoundation/AVAudioPlayer.h> 
#import <UIKit/UIKit.h> 
#import "FSDetailViewController.h" 

@interface FSAnimalsViewController : UITableViewController 
{ 
} 
@end 

.

// 
// FSAnimalsViewController.m 
// FoxSays 
// 
// Created by Scott Pfeiffer on 10/1/13. 
// Copyright (c) 2013 Bradley. All rights reserved. 
// 

#import "FSAnimalsViewController.h" 
#import "FSItemStore.h" 
#import "FSItem.h" 

@implementation FSAnimalsViewController 
- (id)init 
{ 
    // Call the superclass's designated initializer 
    self = [super initWithStyle:UITableViewStyleGrouped]; 
    if (self) 
    { 
     UINavigationItem *n = [self navigationItem]; 

     [n setTitle:@"FoxSays"]; 

     // Create a new bar button item that will send 
     // addNewItem: to ItemsViewController 

     [[self navigationItem] setLeftBarButtonItem:[self editButtonItem]]; 

    } 
    return self; 
} 

- (void)viewWillAppear:(BOOL)animated 
{ 
    [super viewWillAppear:animated]; 
    [[self tableView] reloadData]; 
} 


- (id)initWithStyle:(UITableViewStyle)style 
{ 
    return [self init]; 
} 


- (void)tableView:(UITableView *)aTableView 
didSelectRowAtIndexPath:(NSIndexPath *)indexPath 
{ 
    FSDetailViewController *detailViewController = [[FSDetailViewController alloc] init]; 

    NSArray *items = [[FSItemStore defaultStore] allItems]; 
    FSItem *selectedItem = [items objectAtIndex:[indexPath row]]; 

    // Give detail view controller a pointer to the item object in row 
    [detailViewController setItem:selectedItem]; 

    // Push it onto the top of the navigation controller's stack 
    [[self navigationController] pushViewController:detailViewController 
              animated:YES]; 
} 


- (NSInteger)tableView:(UITableView *)tableView 
numberOfRowsInSection:(NSInteger)section 
{ 
    return [[[FSItemStore defaultStore] allItems] count]; 
} 

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath 
{ 
    // Set the cell identifier 
    static NSString *CellIdentifier = @"BasicCell"; 

    // Reuse the cell from the identifier 
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier forIndexPath:indexPath]; 

    // Configure the cell if it doesn't exist 
    if (!cell) 
    { 
     cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier]; 
    } 

    // Log the row for debugging 
    NSLog(@"%d", [indexPath row]); 

    // Get object from store 
    FSItem *item = [[[FSItemStore defaultStore] allItems] objectAtIndex:[indexPath row]]; 

    // Set label to from property in object 
    [[cell textLabel] setText:[item title]]; 

    return cell; 
} 
+0

Сорта решить мою проблему. я занимался и добавил еще один контроллер представлений, который, по-видимому, работал. Теперь я вижу вкладки в нижней части экрана, и они, похоже, работают, но это дает мне это сообщение: «Двухэтапная анимация вращения устарела. Это приложение должно использовать более плавную одноэтапную анимацию». Я предполагаю, что моя следующая проблема заключается в том, что на одном из моих экранов должна быть кнопка, на которую я могу щелкнуть. Его там в раскадровке, но когда я запустил приложение, он просто отображает черный экран? почему это и что я могу сделать, чтобы исправить это. При необходимости я могу отправить код. –

ответ

0

В AppDelegate, создать элемент вашего основного корневого контроллера

@property (strong, nonatomic) FSHomeViewController * homeViewController 

Затем перед линией

[self.window makeKeyAndVisible]; 

Добавить:

homeViewController = [[FSHomeViewController alloc] init]; 
self.window.rootViewController = homeViewController 

Не забудьте включить заголовки - В "appDelegate.h"

@class FSHomeViewController 

и в "appDelegate.m"

#import "FSHomeViewController" 
+0

Я добавил и побежал. Сбой сборки происходит со следующими ошибками: «использование необъявленного идентификатора« homeViewController »и неизвестного приемника« FSHomeViewController ». –

+0

В appDelegate.h добавьте @class FSHomeViewController И в вашем appDelegate.m добавьте импорт« FSHomeViewController.h » – Jack

+0

i tinkered и нашел работоспособное решение, но я попытался реализовать его, чтобы убедиться, что он сделал все более плавным. Все приложение сработает сейчас! ahhhhh. –

Смежные вопросы