[英]ios:Instatinate View Controller is not working(View Controller is not pushing)?
在我的項目中,從Web服務解析json並顯示在屏幕上,正在為我的項目使用stroyboards;在輸入用戶詳細信息后,在我的登錄頁面中,分析json,我的狀態為1,它將轉到下一頁,否則將顯示錯誤消息。 現在我的問題是它檢查狀態,但沒有加載下一頁。 我正在使用導航控制器。 這是我嘗試加載視圖控制器但我無法正常工作的代碼
-(void)connectionDidFinishLoading:(NSURLConnection *)connection {
NSLog(@"%@",redirectString);
tweet = [[NSDictionary alloc]init];
tweet = [NSJSONSerialization JSONObjectWithData:webData options:NSJSONReadingAllowFragments error:nil];
NSLog(@"%@",tweet);
if ([tweet isKindOfClass:[NSDictionary class]]){ //Added instrospection as suggested in comment.
NSArray *yourStaffDictionaryArray = tweet[@"userDetail"];
if ([yourStaffDictionaryArray isKindOfClass:[NSArray class]]){//Added instrospection as suggested in comment.
for (NSDictionary *dictionary in yourStaffDictionaryArray) {
if([[dictionary objectForKey:@"status"] isEqualToString:@"1"])
{
NSLog(@"%@",[dictionary objectForKey:@"status"]);
NSLog(@"%@",redirectString);
if([redirectString isEqualToString:@"CA"]) {
NSLog(@"Prints 1");
UIStoryboard *storyboard = [UIStoryboard storyboardWithName:@"MainStoryboard_iPhone" bundle:nil];
// Get instance of initial Viewcontroller from storyboard
UINavigationController *navController = self.navigationController;
// Get instance of desired viewcontroller
RTCommunityViewController *viewController =[storyboard instantiateViewControllerWithIdentifier:@"community_id"];
//viewController.kApiKey = apikey;
//viewController.kSessionId = sessionid;
//viewController.kToken = token;
[self.navigationController pushViewController:viewController animated:NO];
}
else if([redirectString isEqualToString:@"CC"]) {
NSLog(@"Prints 1");
UIStoryboard *storyboard = [UIStoryboard storyboardWithName:@"MainStoryboard_iPhone" bundle:nil];
// Get instance of initial Viewcontroller from storyboard
UINavigationController *navController = self.navigationController;
// Get instance of desired viewcontroller
RTCounsellingViewController *viewController =[storyboard instantiateViewControllerWithIdentifier:@"community_id"];
//viewController.kApiKey = apikey;
//viewController.kSessionId = sessionid;
//viewController.kToken = token;
[self.navigationController pushViewController:viewController animated:NO];
}
else if([redirectString isEqualToString:@"mgar"]) {
NSLog(@"Prints 1");
UIStoryboard *storyboard = [UIStoryboard storyboardWithName:@"MainStoryboard_iPhone" bundle:nil];
// Get instance of initial Viewcontroller from storyboard
UINavigationController *navController = self.navigationController;
// Get instance of desired viewcontroller
MyGivingViewController *viewController =[storyboard instantiateViewControllerWithIdentifier:@"community_id"];
//viewController.kApiKey = apikey;
//viewController.kSessionId = sessionid;
//viewController.kToken = token;
[self.navigationController pushViewController:viewController animated:NO];
}
else if([redirectString isEqualToString:@""]){
UIStoryboard *storyboard = [UIStoryboard storyboardWithName:@"MainStoryboard_iPhone" bundle:nil];
NSLog(@"Prints 2");
// Get instance of initial Viewcontroller from storyboard
UINavigationController *navController = [storyboard instantiateViewControllerWithIdentifier:@"MYhome1"];
// Get instance of desired viewcontroller
RTHomeViewController *viewController = (RTHomeViewController *)[navController topViewController];
//viewController.kApiKey = apikey;
//viewController.kSessionId = sessionid;
//viewController.kToken = token;
[self presentViewController:navController animated:NO completion:nil];
}
NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
[SingleTon sinlgeTon].myname = username;
[defaults setObject:username forKey:@"firstname"];
[defaults setObject:pass1 forKey:@"lastname"];
[defaults setObject:valuestat forKey:@"USER_ID"];
[defaults setObject:usertype forKey:@"USER_TYPE"];
[defaults synchronize];
NSLog(@"Data saved");
}
else if([[dictionary objectForKey:@"status"] isEqualToString:@"0"])
{
UIAlertView *newAlert = [[UIAlertView alloc]initWithTitle:@"User Not Enabled!!" message:@"Contact Admin" delegate:nil cancelButtonTitle:@"OK" otherButtonTitles:nil];
[newAlert show];
[user resignFirstResponder];
[pass resignFirstResponder];
user.text = nil;
pass.text = nil;
}
else if([[dictionary objectForKey:@"status"] isEqualToString:@"invalid"]){
UIAlertView *newAlert = [[UIAlertView alloc]initWithTitle:@"Invalid User!!" message:@"Contact Admin" delegate:nil cancelButtonTitle:@"OK" otherButtonTitles:nil];
[newAlert show];
}
}
}
}
}
我在這里打過
UIStoryboard *storyboard = [UIStoryboard storyboardWithName:@"MainStoryboard_iPhone" bundle:nil];
// Get instance of initial Viewcontroller from storyboard
UINavigationController *navController = self.navigationController;
// Get instance of desired viewcontroller
RTCommunityViewController *viewController =[storyboard instantiateViewControllerWithIdentifier:@"community_id"];
//viewController.kApiKey = apikey;
//viewController.kSessionId = sessionid;
//viewController.kToken = token;
[self.navigationController pushViewController:viewController animated:NO];
}
我無法通過實例化加載viewController。 View Controller is not pushing
請幫我怎么做。 提前致謝
嘗試
UIStoryboard *storyboard = [UIStoryboard storyboardWithName:@"MainStoryboard_iPhone" bundle:nil];
UINavigationController *navController = self.navigationController;
RTCommunityViewController *viewController =[storyboard instantiateViewControllerWithIdentifier:@"community_id"];
//Comment this
//[self.navigationController pushViewController:viewController animated:NO];
[self performSegueWithIdentifier:@"community_id" sender:self];
也許您應該再檢查一次故事板? 您是否忘了在身份檢查器中為所有場景設置自定義類和StoryboardID?
在視圖控制器的類似情況下,此代碼對我有用:
RTCommunityViewController *viewController = [self.storyboard instantiateViewControllerWithIdentifier:@"community_id"];
[self.navigationController pushViewController:viewController animated:NO];
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.