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;
}
4

1 回答 1

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"
于 2013-10-14T01:11:23.187 回答