0
我的加載應用程序檢查用戶是否在文件系統中有一個文件,如果沒有,它會彈出一個使用presentModalViewController的視圖控制器,並且在用戶使用該視圖登錄後控制器我的應用程序應該從網上獲取一些數據。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];
}
真的嗎?我認爲模態的全部想法是在視圖完成之前停止一切。這讓我難過。 –
這不是它的工作原理。主運行循環處理所有觸摸事件並繪製屏幕。如果它在呈現之後停止,則不會再進行觸摸事件或屏幕繪製,因此您甚至不會看到模式視圖控制器出現或能夠與其進行交互。 – mattjgalloway
謝謝,我現在正在用文檔破解我的頭腦。 –