首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >ios:Instatinate Controller不工作( View Controller不推送)?

ios:Instatinate Controller不工作( View Controller不推送)?
EN

Stack Overflow用户
提问于 2014-02-25 14:11:31
回答 2查看 192关注 0票数 0

在我的项目中,我正在解析来自webservice的json并显示在屏幕上,我使用stroyboards为我的项目,在我的登录页面中,输入用户详细信息后解析json,是我收到的状态为1,它将转到下一页,否则将显示错误信息。现在我的问题是,它检查状态,但没有加载下一页。我正在使用导航控制器。这是我试图加载的视图控制器的代码,但它不起作用

代码语言:javascript
复制
  -(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];

        }
        }
        }
    }
}

我在这里敲了一下

代码语言:javascript
复制
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请教我怎么做。提前感谢

EN

回答 2

Stack Overflow用户

发布于 2014-02-25 19:27:07

试一试

代码语言:javascript
复制
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];
票数 0
EN

Stack Overflow用户

发布于 2014-02-25 20:54:38

也许你应该再检查一次你的故事板?您不是忘了在身份检查器中为所有场景设置自定义类和StoryboardID了吗?

在视图控制器中类似的情况下,以下代码适用于我:

代码语言:javascript
复制
RTCommunityViewController *viewController = [self.storyboard instantiateViewControllerWithIdentifier:@"community_id"];
[self.navigationController pushViewController:viewController animated:NO];
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/22006039

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档