http://www.uplook.cn/kbase-Index-show-view17674.html
照着这篇文章添加.xib文件,然后又添加了label标签和按钮,可以正常显示控件,但按钮点击不了。关闭重启后控件消失了,为什么?
我用的是Xcode4.2,新建的empty project里没有.xib文件,需要手动添加。
AppDelegate.h文件
#import <UIKit/UIKit.h>
@interface AppDelegate : UIResponder <UIApplicationDelegate>{ UIWindow *window;
UILabel *lab;
}@property (nonatomic,retain) IBOutlet UIWindow *window;@property (nonatomic,retain) IBOutlet UILabel *lab;
- (IBAction)button:(id)sender;@endAppDelegate.m文件
#import "AppDelegate.h"@implementation AppDelegate
//@synthesize view;@synthesize window;
@synthesize lab;- (IBAction)button:(id)sender {
lab.text = @"Hello World!";
}
- (void)dealloc
{
[window release];
[lab release];
[super dealloc];
}- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
self.window = [[[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]] autorelease];
// Override point for customization after application launch.
self.window.backgroundColor = [UIColor orangeColor];
NSLog(@"我已经运行了");
[self.window makeKeyAndVisible];
return YES;
}- (void)applicationWillResignActive:(UIApplication *)application
{
// Sent when the application is about to move from active to inactive state. This can occur for certain types of temporary interruptions (such as an incoming phone call or SMS message) or when the user quits the application and it begins the transition to the background state.
// Use this method to pause ongoing tasks, disable timers, and throttle down OpenGL ES frame rates. Games should use this method to pause the game.
}- (void)applicationDidEnterBackground:(UIApplication *)application
{
// Use this method to release shared resources, save user data, invalidate timers, and store enough application state information to restore your application to its current state in case it is terminated later.
// If your application supports background execution, this method is called instead of applicationWillTerminate: when the user quits.
}- (void)applicationWillEnterForeground:(UIApplication *)application
{
// Called as part of the transition from the background to the inactive state; here you can undo many of the changes made on entering the background.
}- (void)applicationDidBecomeActive:(UIApplication *)application
{
// Restart any tasks that were paused (or not yet started) while the application was inactive. If the application was previously in the background, optionally refresh the user interface.
}- (void)applicationWillTerminate:(UIApplication *)application
{
// Called when the application is about to terminate. Save data if appropriate. See also applicationDidEnterBackground:.
}@end
照着这篇文章添加.xib文件,然后又添加了label标签和按钮,可以正常显示控件,但按钮点击不了。关闭重启后控件消失了,为什么?
我用的是Xcode4.2,新建的empty project里没有.xib文件,需要手动添加。
AppDelegate.h文件
#import <UIKit/UIKit.h>
@interface AppDelegate : UIResponder <UIApplicationDelegate>{ UIWindow *window;
UILabel *lab;
}@property (nonatomic,retain) IBOutlet UIWindow *window;@property (nonatomic,retain) IBOutlet UILabel *lab;
- (IBAction)button:(id)sender;@endAppDelegate.m文件
#import "AppDelegate.h"@implementation AppDelegate
//@synthesize view;@synthesize window;
@synthesize lab;- (IBAction)button:(id)sender {
lab.text = @"Hello World!";
}
- (void)dealloc
{
[window release];
[lab release];
[super dealloc];
}- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
self.window = [[[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]] autorelease];
// Override point for customization after application launch.
self.window.backgroundColor = [UIColor orangeColor];
NSLog(@"我已经运行了");
[self.window makeKeyAndVisible];
return YES;
}- (void)applicationWillResignActive:(UIApplication *)application
{
// Sent when the application is about to move from active to inactive state. This can occur for certain types of temporary interruptions (such as an incoming phone call or SMS message) or when the user quits the application and it begins the transition to the background state.
// Use this method to pause ongoing tasks, disable timers, and throttle down OpenGL ES frame rates. Games should use this method to pause the game.
}- (void)applicationDidEnterBackground:(UIApplication *)application
{
// Use this method to release shared resources, save user data, invalidate timers, and store enough application state information to restore your application to its current state in case it is terminated later.
// If your application supports background execution, this method is called instead of applicationWillTerminate: when the user quits.
}- (void)applicationWillEnterForeground:(UIApplication *)application
{
// Called as part of the transition from the background to the inactive state; here you can undo many of the changes made on entering the background.
}- (void)applicationDidBecomeActive:(UIApplication *)application
{
// Restart any tasks that were paused (or not yet started) while the application was inactive. If the application was previously in the background, optionally refresh the user interface.
}- (void)applicationWillTerminate:(UIApplication *)application
{
// Called when the application is about to terminate. Save data if appropriate. See also applicationDidEnterBackground:.
}@end
解决方案 »
- core text 在iPad中怎样设置位置
- 看了论坛介绍IPHONE的开发环境的安装好复杂,但是专业的苹果论坛一直在介绍给普通的PC机器装苹果的系统,那直接装苹果的系统后,可以装开发环境?
- ios系统,应用程序开发?
- iPhone做USB主机的问题
- 用户登陆注册时验证码的问题
- ios描述文件安装的问题
- 急急急!!!同一个tableViewController的headerView上有个segmentControl,想用来实现本页面上tableView的切换!
- UItableView自定义标题重用问题
- iOS8 导航控制器popToRootViewController
- XCODE 打包出错
- 太难了!对OC中协议和委托理解
- jquery mobile 上传文件的问题
在创建项目的时候选择单试图的类型然后在viewController中添加你那些操作(xib画好后要链接上才可以触发事件的)在或者,只能用代码实现了
如果把window比作是电视机屏幕,view及其它元素相当于电视上显示的人物。window是固定的,而view则是可变的。你在运行时不显示,是因为你只创建了一个window.你的xib文件并没有生效。
你需要把- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions 这个消息中的window实例的创建注释掉,不用代码来创建,而是通过xib来创建self.window = [[[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]] autorelease];
// Override point for customization after application launch.
self.window.backgroundColor = [UIColor orangeColor];上面这些全注释掉。再试试。(确保UIWindow,UILabel 与xib已建立连接)