XIB文件不会出现

时间:2012-03-19 02:11:08

标签: iphone ios xcode uitabbarcontroller xib

创建了一个标签应用程序并创建了第一个包含日期选择器和圆形矩形按钮的XIB文件。问题是当我运行它时,模拟器中没有任何显示。在我已经注释掉的实现文件中,只为BidDatePickerViewController的“不完整实现”收到一个警告。

以下是文件的代码:

ViewController标题:

#import <UIKit/UIKit.h>

@interface BiDDatePickerViewController : UIViewController

@property (strong, nonatomic)IBOutlet UIDatePicker *datePicker;

-(IBAction):buttonPressed;

@end

ViewController实现:

#import "BiDDatePickerViewController.h"

@implementation BiDDatePickerViewController  // Incomplete implementation
@synthesize datePicker;

-(IBAction)buttonPressed
{
    NSDate *selected = [datePicker date];
    NSString *message = [[NSString alloc]initWithFormat:@"The date and time selected is: %@", selected];
    UIAlertView *alert = [[UIAlertView alloc]
                          initWithTitle:@"Date And Time Selected" 
                          message:message 
                          delegate:nil 
                          cancelButtonTitle:@"Yes, I did." 
                          otherButtonTitles:nil];
    [alert show];
}

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

- (void)viewDidLoad
{
    [super viewDidLoad];
    NSDate *now = [NSDate date];
    [datePicker setDate:now animated:NO];
}

- (void)viewDidUnload
{
    [super viewDidUnload];
    // Release any retained subviews of the main view.
    // e.g. self.myOutlet = nil;
    self.datePicker = nil;
}

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
    return (interfaceOrientation == UIInterfaceOrientationPortrait);
}

@end

AppDelegate.m

导入“BiDAppDelegate.h”

@implementation BiDAppDelegate

@synthesize window = _window;
@synthesize rootController;

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
    self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
    // Override point for customization after application launch.
    [[NSBundle mainBundle] loadNibNamed:@"TabBarController" owner:self options:nil];
    [self.window addSubview:rootController.view];
    self.window.backgroundColor = [UIColor whiteColor];
    [self.window makeKeyAndVisible];
    return YES;
}
@end

1 个答案:

答案 0 :(得分:1)

您需要设置rootViewController以在应用程序中显示所需的视图控制器(BiDDatePickerViewController):didFinishLaunchingWithOptions:

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

    self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
    // Override point for customization after application launch.

    [[NSBundle mainBundle] loadNibNamed:@"TabBarController" owner:self options:nil];

    [self.window addSubview:rootController.view];

    self.window.backgroundColor = [UIColor whiteColor];

    [self.window makeKeyAndVisible];

    BiDDatePickerViewController* viewController = [BiDDatePickerViewController new];
    [self.window.rootViewController presentModalViewController:viewController animated:NO];
    [viewController release];
    return YES;
}