我正在尝试制作一个使用标签式浏览的应用。我无法弄清楚如何正确指定我的根控制器和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"