2015-09-01 62 views
-1

JSON輸出:取決於json值我們如何將視圖控制器從一個視圖移動到另一個視圖?

category =  (
       { 
      "category_id" = 1; 
      column = 0; 
      description = ""; 
      image = "images/Car Wash.jpg"; 
      "meta_description" = ""; 
      "meta_keyword" = ""; 
      name = "Car Wash"; 
      "parent_id" = ""; 
      "sort_order" = 0; 
      status = enable; 
      subcategory =    (
           { 
        "category_id" = 6; 
        column = 0; 
        description = ""; 
        image = "images/hatchpack.jpg"; 
        "meta_description" = ""; 
        "meta_keyword" = ""; 
        name = hatchpack; 
        "parent_id" = 1; 
        "sort_order" = 0; 
        status = enable; 
        subcategory =      (
        ); 
        top = ""; 
       } 
      ); 
      top = ""; 
     }, 
       { 
      "category_id" = 2; 
      column = 0; 
      description = ""; 
      image = "images/Pest Control.png"; 
      "meta_description" = ""; 
      "meta_keyword" = ""; 
      name = "Pest Control"; 
      "parent_id" = ""; 
      "sort_order" = 0; 
      status = enable; 
      subcategory =    (
      ); 
      top = ""; 
     }, 
       { 
      "category_id" = 3; 
      column = 0; 
      description = ""; 
      image = "images/Electrician.jpg"; 
      "meta_description" = ""; 
      "meta_keyword" = ""; 
      name = Electrician; 
      "parent_id" = ""; 
      "sort_order" = 0; 
      status = ""; 
      subcategory =    (
      ); 
      top = ""; 
     }, 
       { 
      "category_id" = 4; 
      column = 0; 
      description = ""; 
      image = "images/Washing Machine.jpg"; 
      "meta_description" = ""; 
      "meta_keyword" = ""; 
      name = "Washing Machine"; 
      "parent_id" = ""; 
      "sort_order" = 0; 
      status = ""; 
      subcategory =    (
      ); 
      top = ""; 
     }, 
       { 
      "category_id" = 5; 
      column = 0; 
      description = ""; 
      image = "images/TV Repair.png"; 
      "meta_description" = ""; 
      "meta_keyword" = ""; 
      name = "TV Repair"; 
      "parent_id" = ""; 
      "sort_order" = 0; 
      status = enable; 
      subcategory =    (
      ); 
      top = ""; 
     }, 
       { 
      "category_id" = 6; 
      column = 0; 
      description = ""; 
      image = "images/hatchpack.jpg"; 
      "meta_description" = ""; 
      "meta_keyword" = ""; 
      name = hatchpack; 
      "parent_id" = 1; 
      "sort_order" = 0; 
      status = enable; 
      subcategory =    (
      ); 
      top = ""; 
     } 
    ); 
    success = 1; 
} 

我的代碼:

for(NSDictionary *DicHoleCategories in ArrCategory) 
     { 
      [DicAllValues setObject:[DicHoleCategories objectForKey:@"subcategory"] forKey:@"subcategory"]; 
      [ArrName addObject:DicAllValues]; 
     } 
      //did select row at indexpath method// 
      subCategory = [[ArrName objectAtIndex:indexPath.row] objectForKey:@"subcategory"]; 

    if(subCategory==nil||[subCategory isEqual:@""]) 
     { 
      productScreen *screen = [[productScreen alloc]init]; 
      screen = [self.storyboard instantiateViewControllerWithIdentifier:@"product"]; 
      [self presentViewController:screen animated:YES completion:nil]; 
     } 
     else 
     { 

      CarDetailsVC *car = [[CarDetailsVC alloc]init]; 
      car=[self.storyboard instantiateViewControllerWithIdentifier:@"category"]; 
      [self presentViewController:car animated:YES completion:nil]; 
     } 

在這裏,我已經正確提到我的代碼,獲取子類別值已經完成,我已經比較值是零或字符串是空的,,但只有其他部分工作我必須做的請任何人幫助我。

+0

你當你的NSLog –

+0

打印類別時沒有子類別它給出的NSLog =()@JincySam –

+0

這意味着它返回數組 –

回答

1
for(NSDictionary *DicHoleCategories in ArrCategory) 
    { 
     [DicAllValues setObject:[DicHoleCategories objectForKey:@"subcategory"] forKey:@"subcategory"]; 
     [ArrName addObject:DicAllValues]; 
    } 
//did select row at indexpath method// 
     NSArray *subCategory=[[ArrName objectAtIndex:indexPath.row] objectForKey:@"subcategory"]; 
if(subCategory.count ==0)//subcategory is an array 
    { 
     productScreen *screen=[[productScreen alloc]init]; 
     screen =[self.storyboard instantiateViewControllerWithIdentifier:@"product"]; 
     [self presentViewController:screen animated:YES completion:nil]; 
    } 
    else 
    { 

     CarDetailsVC *car=[[CarDetailsVC alloc]init]; 
     car=[self.storyboard instantiateViewControllerWithIdentifier:@"category"]; 
     [self presentViewController:car animated:YES completion:nil]; 
    } 
+0

該子類別是一個NSString ...... –

+0

將子類別從NSString更改爲NSArray –

+0

si已更改該NSArray現在其工作... .. –

0

你已經給& &條件裏面if語句。兩種情況都不能同時發生。而且,用isEqualToString方法檢查你的字符串。 所以,把你如果條件下面給出 -

if([subcategory length] ==0){ 
    // Your code goes here. 
} 
+0

試過這個也是兄弟....但是不起作用 –

+0

檢查子類別的長度。如果([子類別長度] == 0) –

+0

它給出錯誤..... –

相關問題