gpt4 book ai didi

iphone - XIB 文件不出现

转载 作者:行者123 更新时间:2023-11-29 04:45:11 25 4
gpt4 key购买 nike

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

以下是文件的代码:

ViewController header :

#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

最佳答案

您需要设置 rootViewController 以在应用程序中显示您想要的 View Controller (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;
}

关于iphone - XIB 文件不出现,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9764174/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com