Reputation: 3917
Have created a tab application and created the first XIB file which includes a date picker and round rect button. Problem is when I run it, nothing displays in the simulator. Only get one warning for "incomplete implementation" for BidDatePickerViewController in the implementation file which I have commented out.
Here is the code for the files:
ViewController header:
#import <UIKit/UIKit.h>
@interface BiDDatePickerViewController : UIViewController
@property (strong, nonatomic)IBOutlet UIDatePicker *datePicker;
-(IBAction):buttonPressed;
@end
ViewController implementation:
#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
@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
Upvotes: 0
Views: 464
Reputation: 1138
You need to set the rootViewController to show the view controller you want (BiDDatePickerViewController) in the application: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;
}
Upvotes: 1
Reputation: 3020
-(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;
}
Upvotes: 0