我的代码在iOS5上工作正常但在iOS4.3上无效,我试图在导航控制器中显示带有进度条的加载屏幕,其中UIViewController
为根视图。
问题是在iOS4.3上加载屏幕没有出现在正确的时间,它出现在第二个视图控制器的视图显示之前,然后很快消失。
以下是代码:
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
self.window = [[[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]] autorelease];
// Override point for customization after application launch.
NSUserDefaults * standardUserDefaults = [NSUserDefaults standardUserDefaults];
CGSize s = [[UIScreen mainScreen] bounds].size;
[standardUserDefaults setObject:@"" forKey:@"display_resolution"];
if((int)s.width == 640 && (int)s.height == 960)[standardUserDefaults setObject:@"@2x" forKey:@"display_resolution"];
[standardUserDefaults synchronize];
AC_Loading *loading = [[[AC_Loading alloc] initWithNibName:@"AC_Loading_iPhone" bundle:nil] autorelease];
_navController0 = [[[UINavigationController alloc]initWithRootViewController:loading]autorelease];
_navController0.navigationBar.hidden = YES;
self.window.rootViewController = self.navController0;
[self.window makeKeyAndVisible];
return YES;
}
-
我发现问题来自AC_Loading's
代码,这个UIViewController
必须显示一个加载屏幕,其中包含根据数据库统计信息更新的进度视图(我正在创建一个sqlite3数据库并更新如果需要并显示进度)。虽然在iOS5上使用此代码但它不在iOS4.x上我认为是因为viewDidAppear内部的循环(而pr< 1.0):
#import "AC_Loading.h"
#import "database.h"
#import "AC_Menu.h"
@implementation AC_Loading
@synthesize logo;
@synthesize progress;
@synthesize informations;
@synthesize CLController;
float pr = 0.14;
int p = 0;
AC_Menu *menu;
NSUserDefaults *standardUserDefaults;
- (void)didReceiveMemoryWarning
{
[super didReceiveMemoryWarning];
}
- (void)viewDidLoad
{
[super viewDidLoad];
standardUserDefaults = [NSUserDefaults standardUserDefaults];
[standardUserDefaults setObject:@"NO" forKey:@"geoloc"];
[standardUserDefaults synchronize];
NSLog(@"%@", [NSString stringWithFormat:@"intro%@%@", [standardUserDefaults stringForKey:@"display_resolution"], @".jpg"]);
[logo setImage:[UIImage imageNamed:[NSString stringWithFormat:@"intro%@%@", [standardUserDefaults stringForKey:@"display_resolution"], @".jpg"]]];
//[progress setProgressTintColor:[UIColor purpleColor]];
[progress setProgress:0.14];
// Do any additional setup after loading the view, typically from a nib.
}
- (void)viewDidUnload
{
[self setLogo:nil];
[self setInformations:nil];
[self setProgress:nil];
[super viewDidUnload];
// Release any retained subviews of the main view.
// e.g. self.myOutlet = nil;
}
- (void)viewWillAppear:(BOOL)animated
{
[super viewWillAppear:YES];
}
- (void)viewDidAppear:(BOOL)animated
{
[super viewDidAppear:YES];
database *DB = [[database alloc] init];
[DB checkDB];
NSString *message = @"Chargement des données";
if([DB isCreated]== NO && [DB upToDate] == NO && sqlite3_open([[DB getDBPath:[NSString stringWithFormat:@"%@%@%@", @"Restaurant_V", [DB getVersion], @".sqlite" ]] UTF8String], [DB getDB]) == SQLITE_OK)
{
message = @"Mise à jour des données";
[DB setExecuting:YES];
[NSThread detachNewThreadSelector:@selector(createDB) toTarget:DB withObject:nil];
while([DB isExecuting]==YES)
{
if([DB isExecuting]==NO) break;
}
NSLog(@"Cas 1");
}
if([DB isCreated]== YES && [DB upToDate] == NO && sqlite3_open([[DB getDBPath:[NSString stringWithFormat:@"%@%@%@", @"Restaurant_V", [DB getVersion], @".sqlite" ]] UTF8String], [DB getDB]) == SQLITE_OK)
{
[DB setExecuting:YES];
[NSThread detachNewThreadSelector:@selector(updateDB:) toTarget:DB withObject:[DB getVersion]];
while([DB isExecuting]==YES)
{
if([DB isExecuting]==NO) break;
}
NSLog(@"Cas 2");
}
int p = floor([progress progress]*100);
while (pr<1.0)
{
p = floor(pr*100);
if(p%14==0)
{
CFRunLoopRunInMode (kCFRunLoopDefaultMode, 0, true);
[progress setProgress:pr];
[informations setText:[NSString stringWithFormat:@"%@ (%d%@", message, p, @"%)"]];
}
pr += 0.000002;
}
[progress setProgress:1.0];
[informations setText:[NSString stringWithFormat:@"%@ (100%@", message, @"%)"]];
menu =
[[[AC_Menu alloc] initWithNibName:@"AC_Menu_iPhone" bundle:nil] autorelease];
[self.navigationController pushViewController:menu animated:YES];
[DB release];
CLController = [[CoreLocationController alloc] init];
CLController.delegate = self;
[CLController.locMgr startUpdatingLocation];
}
- (void)dealloc {
[CLController release];
[logo release];
[informations release];
[progress release];
[super dealloc];
}