main.m代码如下:
#import <UIKit/UIKit.h>
#import "AppDelegate.h"
int main(int argc, char *argv[])
{
NSAutoreleasePool * pool = [[NSAutoreleasePool alloc] init];
int retVal = UIApplicationMain(argc, argv, nil, NSStringFromClass([AppDelegate class]));
//int retVal = UIApplicationMain(argc, argv, nil, nil);
[pool release];
return retVal;
}
AppDelegate.m代码如下:
#import "AppDelegate.h"
#import "ViewController.h"
#import "LeadingViewControllerViewController.h"
@implementation AppDelegate
@synthesize window = _window;
@synthesize viewController = _viewController;
@synthesize leadingViewController = _leadingViewController;
- (void)dealloc
{
[_window release];
[_viewController release];
[_leadingViewController release];
[super dealloc];
}
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
//在启动画面消失前增加3秒延时
[NSThread sleepForTimeInterval:3];
self.window = [[[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]] autorelease];
// Override point for customization after application launch.
if ([[UIDevice currentDevice] userInterfaceIdiom] == UIUserInterfaceIdiomPhone)
{
self.viewController = [[[ViewController alloc] initWithNibName:@"ViewController_iPhone" bundle:nil] autorelease];
}
else
{
self.viewController = [[[ViewController alloc] initWithNibName:@"ViewController_iPad" bundle:nil] autorelease];
}
[self.window addSubview:self.viewController.view];
if (![self getUsed])
{
self.leadingViewController = [[[LeadingViewControllerViewController alloc] init] autorelease];
[self.window addSubview:self.leadingViewController.view];
[self saveUsed];
}
/*
self.leadingViewController = [[[LeadingViewControllerViewController alloc] init] autorelease];
[self.window addSubview:self.leadingViewController.view];
[self saveUsed];*/
[self.window makeKeyAndVisible];
return YES;
}
//存储用户第一次使用该app的信息
- (void) saveUsed
{
NSUserDefaults *standardUserDefaults = [NSUserDefaults standardUserDefaults];
if (standardUserDefaults)
{
[standardUserDefaults setBool:TRUE forKey:@"RhineSplash1.9_Used"];
[standardUserDefaults synchronize];
}
}
//获取用户是否已经使用过该app
- (BOOL) getUsed
{
BOOL val = NO;
NSUserDefaults *standardUserDefaults = [NSUserDefaults standardUserDefaults];
if (standardUserDefaults)
{
val = [standardUserDefaults boolForKey:@"RhineSplash1.9_Used"];
}
return val;
}
- (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
9 个解决方案
#1
没有人知道吗?
#2
真机调试一下嘛
#3
是真机调试的,才有这样的错误。
#4
@synthesize viewController = _viewController;
[_viewController release];
self.viewController = [[[ViewController alloc] initWithNibName:@"ViewController_iPhone" bundle:nil] autorelease];
viewController释放两次了!
[_viewController release];
self.viewController = [[[ViewController alloc] initWithNibName:@"ViewController_iPhone" bundle:nil] autorelease];
viewController释放两次了!
#5
这里应该是释放一次,确认这些参数
_window、_viewController、_leadingViewController设置的属性声明有没有设置成assign
#6
建议楼主用ARC,基本上不需要担心内存泄露了。
可以通过Xcode中的 Edit/Refactor/Convert to Ojbective-C ARC 来实现把代码升级到ARC
可以通过Xcode中的 Edit/Refactor/Convert to Ojbective-C ARC 来实现把代码升级到ARC
#7
#8
这个可以有
#9
initWithNibName:@"ViewController_iPhone" bundle:nil
这个不太用,你看看是不是XIB文件对应上了。
//在启动画面消失前增加3秒延时
[NSThread sleepForTimeInterval:3];
这个是不是也是一个原因。。。貌似真机 启动,3秒的停留 会让 系统认为 可以关闭这个app 了
其他的具体也看不出什么问题,你设置断点看看,log打印出什么东西,加以分析。
这个不太用,你看看是不是XIB文件对应上了。
//在启动画面消失前增加3秒延时
[NSThread sleepForTimeInterval:3];
这个是不是也是一个原因。。。貌似真机 启动,3秒的停留 会让 系统认为 可以关闭这个app 了
其他的具体也看不出什么问题,你设置断点看看,log打印出什么东西,加以分析。
#1
没有人知道吗?
#2
真机调试一下嘛
#3
是真机调试的,才有这样的错误。
#4
@synthesize viewController = _viewController;
[_viewController release];
self.viewController = [[[ViewController alloc] initWithNibName:@"ViewController_iPhone" bundle:nil] autorelease];
viewController释放两次了!
[_viewController release];
self.viewController = [[[ViewController alloc] initWithNibName:@"ViewController_iPhone" bundle:nil] autorelease];
viewController释放两次了!
#5
这里应该是释放一次,确认这些参数
_window、_viewController、_leadingViewController设置的属性声明有没有设置成assign
#6
建议楼主用ARC,基本上不需要担心内存泄露了。
可以通过Xcode中的 Edit/Refactor/Convert to Ojbective-C ARC 来实现把代码升级到ARC
可以通过Xcode中的 Edit/Refactor/Convert to Ojbective-C ARC 来实现把代码升级到ARC
#7
#8
这个可以有
#9
initWithNibName:@"ViewController_iPhone" bundle:nil
这个不太用,你看看是不是XIB文件对应上了。
//在启动画面消失前增加3秒延时
[NSThread sleepForTimeInterval:3];
这个是不是也是一个原因。。。貌似真机 启动,3秒的停留 会让 系统认为 可以关闭这个app 了
其他的具体也看不出什么问题,你设置断点看看,log打印出什么东西,加以分析。
这个不太用,你看看是不是XIB文件对应上了。
//在启动画面消失前增加3秒延时
[NSThread sleepForTimeInterval:3];
这个是不是也是一个原因。。。貌似真机 启动,3秒的停留 会让 系统认为 可以关闭这个app 了
其他的具体也看不出什么问题,你设置断点看看,log打印出什么东西,加以分析。