运行构建时 UINavigationController 未显示

发布于 2024-11-16 00:37:15 字数 2519 浏览 3 评论 0原文

编辑:工作,请参阅下面的代码。

正在开发一个应用程序,现在我有 AppDelegate 类和自定义 UINavigationController 类。我现在的代码非常简单,我觉得我已经正确设置了 XIB 。构建成功,没有错误。但是当应用程序启动时,导航控制器不会显示。我没有看到导航栏,也没有看到表格视图。我所看到的只是一个空白屏幕。这是我的大部分代码:

//
//  FTPPhotosAppDelegate.h
//  FTPPhotos
//
//  Created by Aaron McLeod on 11-05-30.
//  Copyright 2011 __MyCompanyName__. All rights reserved.
//

#import <UIKit/UIKit.h>
#import "RootViewController.h"

@interface FTPPhotosAppDelegate : NSObject <UIApplicationDelegate> {
    UINavigationController *navigationController;
    RootViewController *rootViewController;
}

@property (nonatomic, retain) UINavigationController *navigationController;
@property (nonatomic, retain) IBOutlet UIWindow *window;

@property (nonatomic, retain) RootViewController *rootViewController;

@end


//
//  FTPPhotosAppDelegate.m
//  FTPPhotos
//
//  Created by Aaron McLeod on 11-05-30.
//  Copyright 2011 __MyCompanyName__. All rights reserved.
//

#import "FTPPhotosAppDelegate.h"

@implementation FTPPhotosAppDelegate


@synthesize window=_window;

    @synthesize navigationController, rootViewController;

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
    navigationController = [[UINavigationController alloc] init];

    rootViewController = [[RootViewController alloc] init];
    [self.navigationController pushViewController:rootViewController animated:NO];
    [self.window addSubview:[self.navigationController view]];    
    [self.window makeKeyAndVisible];
    return YES;
}


@interface RootViewController : UITableViewController<UIImagePickerControllerDelegate> {
    NSMutableArray *photos;
    UIImagePickerController *picker;
    UIBarButtonItem *addPhotoButton;
}

@property (nonatomic, retain) NSMutableArray *photos;
@property (nonatomic, retain) UIImagePickerController *picker;
@property (nonatomic, retain) IBOutlet UIBarButtonItem *addPhotoButton;

- (void) loadPhotos;
- (IBAction) addPhoto;
- (UIImage*)imageWithImage:(UIImage*)image scaledToSize:(CGSize)newSize;
@end


#import "RootViewController.h"

@implementation RootViewController
@synthesize photos, picker, addPhotoButton;

- (void)viewDidLoad
{
    self.photos = [[NSMutableArray alloc] initWithCapacity:50];
    [self loadPhotos];
    [super viewDidLoad];
}

有什么想法吗?这是 XIB 的屏幕截图,

http://img148.imageshack.us/img148/189/笔尖.png

如果您需要更多信息,请告诉我。

EDIT: Working, see code below.

Working on an application, where right now I have the AppDelegate class, and a custom UINavigationController class. The code i have right now is pretty simple, and I feel like I've setup the XIB correctly. The build succeeds with no errors. But when the app launches, the navigationcontroller isnt displayed. I do not see the nav bar nor the table view. All I see is a blank screen. Here's the bulk of my code:

//
//  FTPPhotosAppDelegate.h
//  FTPPhotos
//
//  Created by Aaron McLeod on 11-05-30.
//  Copyright 2011 __MyCompanyName__. All rights reserved.
//

#import <UIKit/UIKit.h>
#import "RootViewController.h"

@interface FTPPhotosAppDelegate : NSObject <UIApplicationDelegate> {
    UINavigationController *navigationController;
    RootViewController *rootViewController;
}

@property (nonatomic, retain) UINavigationController *navigationController;
@property (nonatomic, retain) IBOutlet UIWindow *window;

@property (nonatomic, retain) RootViewController *rootViewController;

@end


//
//  FTPPhotosAppDelegate.m
//  FTPPhotos
//
//  Created by Aaron McLeod on 11-05-30.
//  Copyright 2011 __MyCompanyName__. All rights reserved.
//

#import "FTPPhotosAppDelegate.h"

@implementation FTPPhotosAppDelegate


@synthesize window=_window;

    @synthesize navigationController, rootViewController;

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
    navigationController = [[UINavigationController alloc] init];

    rootViewController = [[RootViewController alloc] init];
    [self.navigationController pushViewController:rootViewController animated:NO];
    [self.window addSubview:[self.navigationController view]];    
    [self.window makeKeyAndVisible];
    return YES;
}


@interface RootViewController : UITableViewController<UIImagePickerControllerDelegate> {
    NSMutableArray *photos;
    UIImagePickerController *picker;
    UIBarButtonItem *addPhotoButton;
}

@property (nonatomic, retain) NSMutableArray *photos;
@property (nonatomic, retain) UIImagePickerController *picker;
@property (nonatomic, retain) IBOutlet UIBarButtonItem *addPhotoButton;

- (void) loadPhotos;
- (IBAction) addPhoto;
- (UIImage*)imageWithImage:(UIImage*)image scaledToSize:(CGSize)newSize;
@end


#import "RootViewController.h"

@implementation RootViewController
@synthesize photos, picker, addPhotoButton;

- (void)viewDidLoad
{
    self.photos = [[NSMutableArray alloc] initWithCapacity:50];
    [self loadPhotos];
    [super viewDidLoad];
}

Any ideas? Here's a screenshot of the XIB,

http://img148.imageshack.us/img148/189/nib.png.

Let me know if you need more info.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

天涯沦落人 2024-11-23 00:37:15

使其成为 UINavigationController *navigationController,而不是根视图控制器。

然后在 applicationDidFinishLaunching 中,说

navigationController = [[UINavigationController alloc]init];
FirstViewController *firstView = [FirstViewController alloc]init];
[self pushViewController:firstView animated:NO];
firstView.title = @"TITLE";
[self addSubview:navigationController.view];

编辑:我的应用程序中的一些示例代码

AppDelegate.h

#import <UIKit/UIKit.h>

@interface DragonAge2AppDelegate : NSObject <UIApplicationDelegate> {
UIWindow *window;
UINavigationController *navigationController;
}

@property (nonatomic, retain) IBOutlet UIWindow *window;

@end

AppDelegate.m

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {    
TitleClass *titlePage = [[TitleClass alloc]init];

navigationController = [[UINavigationController alloc]init];
titlePage.title = @"Dragon Age 2";
[navigationController pushViewController:titlePage animated:NO];
[titlePage release];

// Override point for customization after application launch.
[window addSubview:navigationController.view];
[self.window makeKeyAndVisible];

return YES;
}

Instead of a root View controller, make it a UINavigationController *navigationController.

then in the applicationDidFinishLaunching, say

navigationController = [[UINavigationController alloc]init];
FirstViewController *firstView = [FirstViewController alloc]init];
[self pushViewController:firstView animated:NO];
firstView.title = @"TITLE";
[self addSubview:navigationController.view];

EDIT: some example code i have in an app of mine

AppDelegate.h

#import <UIKit/UIKit.h>

@interface DragonAge2AppDelegate : NSObject <UIApplicationDelegate> {
UIWindow *window;
UINavigationController *navigationController;
}

@property (nonatomic, retain) IBOutlet UIWindow *window;

@end

AppDelegate.m

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {    
TitleClass *titlePage = [[TitleClass alloc]init];

navigationController = [[UINavigationController alloc]init];
titlePage.title = @"Dragon Age 2";
[navigationController pushViewController:titlePage animated:NO];
[titlePage release];

// Override point for customization after application launch.
[window addSubview:navigationController.view];
[self.window makeKeyAndVisible];

return YES;
}
戴着白色围巾的女孩 2024-11-23 00:37:15

您需要检查以下几点:

  • 运行应用程序时是否执行了 application:didFinishLaunchingWithOptions: 中的代码?在此代码中添加 NSLog(@"app launch") 或在其中设置断点来检查它。如果未调用它,则您的 FTPPhotosAppDelegate 对象可能未设置为 XIB 中的 UIApplication 单例的委托(此连接应该完成默认情况下,如果您使用标准模板创建应用程序,但值得检查)
  • AppDelegate 的 navigationController IBOutlet 是否正确连接到您实际的 UINavigationController在 XIB 中?检查(使用 NSLog 或断点)它不是 nil。
  • 对于 XIBUINavigationController 对象的视图 IBOutlet 也是如此:检查它是否正确连接,而不是 nil

You need to check some points:

  • Is the code in application:didFinishLaunchingWithOptions: executed when you run the application? Add a NSLog(@"app launched") in this code or set a breakpoint in it to check it. If it is not called, your FTPPhotosAppDelegate object is probably not set as the delegate of your UIApplication singleton in the XIB (this connection should be done by default if you created your app using a standard template, but it's worth checking)
  • Is the navigationController IBOutlet of your AppDelegate properly connected to your actual UINavigationController in the XIB? Check (using an NSLog or a breakpoint) that it is not nil.
  • Same for the view IBOutlet of the UINavigationController object in your XIB: check that it is properly connected and not nil.
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文