我的是xcode 4.6 ,在didFinishLaunchingWithOptions中想手动添加按钮,但是按钮不显示。请问:在这个函数里能否手动添加按钮?如果能添加,则要有哪些需要注意的地方???
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
self.window = [[[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]] autorelease];
// Override point for customization after application launch.
self.viewController = [[[FQViewController alloc] initWithNibName:@"FQViewController" bundle:nil] autorelease];
self.window.rootViewController = self.viewController; [self.window makeKeyAndVisible];
//这里的button没有显示,麻烦各位帮忙看一下问题出哪了。我初学者,不太清楚
UIButton *button = [UIButton buttonWithType:UIButtonTypeRoundedRect];
[button setTitle:@"点击" forState:UIControlStateNormal];
[button setTag:100];
[button setFrame:CGRectMake(30, 40, 60, 40)];
[self.window addSubview:(UIView *)button];
[button release];//这里添加的view就能显示
// UIView *view = [[UIView alloc] initWithFrame:CGRectMake(40, 50, 60, 60)];
// view.backgroundColor = [UIColor redColor];
// [self.window addSubview:view];
// [view release];
return YES;
}手动添加按钮didFinishLaunching
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
self.window = [[[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]] autorelease];
// Override point for customization after application launch.
self.viewController = [[[FQViewController alloc] initWithNibName:@"FQViewController" bundle:nil] autorelease];
self.window.rootViewController = self.viewController; [self.window makeKeyAndVisible];
//这里的button没有显示,麻烦各位帮忙看一下问题出哪了。我初学者,不太清楚
UIButton *button = [UIButton buttonWithType:UIButtonTypeRoundedRect];
[button setTitle:@"点击" forState:UIControlStateNormal];
[button setTag:100];
[button setFrame:CGRectMake(30, 40, 60, 40)];
[self.window addSubview:(UIView *)button];
[button release];//这里添加的view就能显示
// UIView *view = [[UIView alloc] initWithFrame:CGRectMake(40, 50, 60, 60)];
// view.backgroundColor = [UIColor redColor];
// [self.window addSubview:view];
// [view release];
return YES;
}手动添加按钮didFinishLaunching
解决方案 »
免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货