Tuesday, September 24, 2013

Novice: didFinishLaunchingWithOptions manually add button is not displayed

I was xcode 4.6, in didFinishLaunchingWithOptions want to manually add the button, but the button is not displayed. I ask you: In this function can manually add button? If you can add, you have what needs attention? ? ?
 - (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];

/ / Here the button is not displayed, the trouble you help look where the problem lies. I'm a beginner, not sure
UIButton * button = [UIButton buttonWithType: UIButtonTypeRoundedRect];
[Button setTitle: @ "Click" forState: UIControlStateNormal];
[Button setTag: 100];
[Button setFrame: CGRectMake (30, 40, 60, 40)];

[Self.window addSubview: (UIView *) button];
[Button release];

/ / Add the view can be displayed here
/ / UIView * view = [[UIView alloc] initWithFrame: CGRectMake (40, 50, 60, 60)];
/ / View.backgroundColor = [UIColor redColor];
/ / [Self.window addSubview: view];
/ / [View release];

return YES;

}
Reply:
I know, the button release to remove the line
Reply:
Or it with ARC

No comments:

Post a Comment