运行构建时 UINavigationController 未显示
编辑:工作,请参阅下面的代码。
正在开发一个应用程序,现在我有 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
的屏幕截图,
。
如果您需要更多信息,请告诉我。
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
,
.
Let me know if you need more info.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
使其成为
UINavigationController *navigationController
,而不是根视图控制器。然后在
applicationDidFinishLaunching
中,说编辑:我的应用程序中的一些示例代码
AppDelegate.h
AppDelegate.m
Instead of a root View controller, make it a
UINavigationController *navigationController
.then in the
applicationDidFinishLaunching
, sayEDIT: some example code i have in an app of mine
AppDelegate.h
AppDelegate.m
您需要检查以下几点:
application:didFinishLaunchingWithOptions:
中的代码?在此代码中添加NSLog(@"app launch")
或在其中设置断点来检查它。如果未调用它,则您的 FTPPhotosAppDelegate 对象可能未设置为 XIB 中的 UIApplication 单例的委托(此连接应该完成默认情况下,如果您使用标准模板创建应用程序,但值得检查)navigationController
IBOutlet
是否正确连接到您实际的UINavigationController
在 XIB 中?检查(使用 NSLog 或断点)它不是 nil。XIB
中UINavigationController
对象的视图IBOutlet
也是如此:检查它是否正确连接,而不是nil
。You need to check some points:
application:didFinishLaunchingWithOptions:
executed when you run the application? Add aNSLog(@"app launched")
in this code or set a breakpoint in it to check it. If it is not called, yourFTPPhotosAppDelegate
object is probably not set as the delegate of yourUIApplication
singleton in theXIB
(this connection should be done by default if you created your app using a standard template, but it's worth checking)navigationController
IBOutlet
of your AppDelegate properly connected to your actualUINavigationController
in theXIB
? Check (using anNSLog
or a breakpoint) that it is notnil
.IBOutlet
of theUINavigationController
object in yourXIB
: check that it is properly connected and notnil
.