【发布时间】:2012-01-16 22:51:39
【问题描述】:
我的应用程序在加载时检查用户是否在文件系统中有文件,如果没有,它会使用 presentModalViewController 弹出一个视图控制器,并且在用户使用该视图控制器登录后,我的应用程序应该得到一些来自网络的数据。
我的问题是在presentModalViewController之后视图控制器确实弹出,但是presentModalViewController之后的代码继续运行而不等待VC返回。
我的代码:
- (void)viewDidLoad
{
[self getPasswordFromFile];
responseData = [[NSMutableData data] retain];
NSString *URL= [NSString stringWithFormat:@"http://localhost/domything/get_status.php?ownerid=%@", nOwnerID];
NSURLRequest *request = [NSURLRequest requestWithURL:[NSURL URLWithString:URL]];
[[NSURLConnection alloc] initWithRequest:request delegate:self];
[super viewDidLoad];
}
-(void)getPasswordFromFile
{
NSArray *arrayPaths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *docDirectory = [arrayPaths objectAtIndex:0];
NSString *filePath = [docDirectory stringByAppendingString:@"/pwfile"];
NSError *error;
NSString *fileContents = [NSString stringWithContentsOfFile:filePath encoding:NSUTF8StringEncoding error:&error];
if(fileContents==nil)
{
// Show registration screen
LoginScreenVC *vcLoginScreen = [[[LoginScreenVC alloc] init] autorelease];
[vcLoginScreen setModalTransitionStyle:UIModalTransitionStyleCrossDissolve];
[self presentModalViewController:vcLoginScreen animated:YES];
}
NSArray *arr = [fileContents componentsSeparatedByString:@":"];
// NSLog(@"ownerid is:%@, password is: %@", [arr objectAtIndex:0], [arr objectAtIndex:1]);
password = [arr objectAtIndex:1];
nOwnerID = [arr objectAtIndex:0];
[password retain];
[nOwnerID retain];
}
【问题讨论】:
标签: ios xcode modalviewcontroller