Question

I think it could be a stupid mistake but I just couldn't figure it out. Can anyone tell me what do I missing??

-(void) receiveRecommendData {
 //receive data//
 NSURL *getResultUrl = [NSURL URLWithString:@"http://phdprototype.tk/getResultData.php"];

 NSData *data = [NSData dataWithContentsOfURL:getResultUrl];

 [self getData:data];

 NSDictionary *jsonToDict = json[0]; //[json objectAtIndex:0];

 int pageNumber = [[jsonToDict objectForKey:@"recommendData"]intValue];

 switch (pageNumber) {
     case 0:
         UIViewController *controller = [self.storyboard instantiateViewControllerWithIdentifier:@"Collection_01ViewController"];
         break;
     case 1:
         UIViewController *controller = [self.storyboard instantiateViewControllerWithIdentifier:@"Collection_01ViewController"];
         break;
     case 2:
          UIViewController *controller = [self.storyboard instantiateViewControllerWithIdentifier:@"Collection_02ViewController"];
          break;
     case 3:
          UIViewController *controller = [self.storyboard instantiateViewControllerWithIdentifier:@"Collection_03ViewController"];
         break;
     default:
         break;
 }
}

the errors occurred on the codes of

UIViewController *controller = [self.storyboard instantiateViewControllerWithIdentifier:@"Collection_01ViewController"]; 

No correct solution

OTHER TIPS

You can't declare a variable as the first line of a case section. Just add braces...

switch (pageNumber) {
  case 0: {
     UIViewController *controller = [self.storyboard instantiateViewControllerWithIdentifier:@"Collection_01ViewController"];
     break;
  }
  case 1: {
     UIViewController *controller = [self.storyboard instantiateViewControllerWithIdentifier:@"Collection_01ViewController"];
     break;
  }
  case 2:  //etc
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top