在我的项目中,我正在解析来自webservice的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请教我怎么做。提前感谢
发布于 2014-02-25 19:27:07
试一试
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];发布于 2014-02-25 20:54:38
也许你应该再检查一次你的故事板?您不是忘了在身份检查器中为所有场景设置自定义类和StoryboardID了吗?
在视图控制器中类似的情况下,以下代码适用于我:
RTCommunityViewController *viewController = [self.storyboard instantiateViewControllerWithIdentifier:@"community_id"];
[self.navigationController pushViewController:viewController animated:NO];https://stackoverflow.com/questions/22006039
复制相似问题