[英]Login Screen+Table View in a Tab Controller= Nothing showing up after initial Login
這個有點復雜〜
獲得了一個登錄頁面,該頁面可驗證來自異地服務器的用戶名/密碼。 服務器返回一個用戶ID,然后在我的應用中使用該ID查找匹配的plist文件。 如果還沒有,則應該使用示例數據為該用戶創建一個新的plist。 所有這些都有效,但是除非我終止然后重新啟動應用程序,否則什么都不會出現。
我認為問題在於tableview與模式登錄頁面同時加載。
以下是我的登錄頁面中的代碼:
-(void)connectionDidFinishLoading:(NSURLConnection *)connection{
[fIndicator stopAnimating];
//convert data from server to a string
NSString *xmlReturn = [[NSString alloc] initWithData:xmlData encoding:NSUTF8StringEncoding];
//notify user if username/pass failed
if ([xmlReturn isEqualToString:@"0"] ||[xmlReturn isEqualToString:@"No"] ) {
UIAlertView *alert =[[UIAlertView alloc]initWithTitle:@"Login Fail" message:nil delegate:nil cancelButtonTitle:@"Retry" otherButtonTitles:nil];
[alert show];
[alert release];
}
//if server authenticates username/pass
else {
NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
//set user ID from server into Defaults for app use
[defaults setObject:xmlReturn forKey:@"AppPref_UI"];
[defaults synchronize];
//this is where I think the tableview needs to be told to reload
//but no idea how to reference that view controller from
//this modal view controller
[??? reloadData];
[self dismissModalViewControllerAnimated:YES];
}
[xmlReturn release];
}
您將使用委托設計模式。 登錄對話框將告訴其委托人何時完成。
@property (nonatomic, assign) id <YourProtocol> delegate;
和
if ([self.delegate respondsToSelector:@selector(loginCompleted:)]) {
[self.delegate loginCompleted:self];
}
在創建登錄視圖控制器並將其呈現給用戶時,您將設置委托。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.