2012-03-19 193 views
0

已經創建了一個選項卡應用程序並創建了第一個包含日期選擇器和圓形按鈕的XIB文件。問題是當我運行它時,模擬器中沒有顯示。在我已經註釋過的實現文件中,僅對BidDatePickerViewController的「不完整實現」發出警告。不顯示XIB文件

下面是文件的代碼:

視圖控制器頭:

#import <UIKit/UIKit.h> 

@interface BiDDatePickerViewController : UIViewController 

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

-(IBAction):buttonPressed; 

@end 

視圖控制器實現:

#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

您需要設置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; 
} 
0
-(BOOL) application: (UIApplication *) application didFinishLaunchingWithOptions (NSDictionary *) launchOptions 

{ 

    self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]]; 

    self.window.backgroundColor = [UIColor whiteColor]; 

    BiDDatePickerViewController* viewController = [[BiDDatePickerViewController alloc]initWithNibName:@"TabBarController" bundle:nil]; 
    [self.window addSubview:rootController.view]; 
    [self.window makeKeyAndVisible]; 
    [viewController release]; 
     return YES; 
}