2016-03-10 66 views
0

當我呼叫以下方法_productName.text = _productInfo.Name 代碼在這裏停止並通過斷點調試拋出錯誤。***終止應用程序,由於未捕獲異常'NSInvalidArgumentException',原因:' - [__ NSDictionaryM名稱]:無法識別的選擇器發送到實例

請指導我....

謝謝!這裏是我的代碼:

-(void)setProductInfo:(OnGoProducts*)prduct 
{ 

    _productInfo = prduct; 
    _productName.text = _productInfo.Name; 
    NSDictionary* dict = [_productInfo.json objectFromJSONString]; 
    _productPrice.text = [dict objectForKey:@"MRP"]; 

    if([self.productInfo.type isEqualToString:@"Deals"]) 
    { 
     [self.shownProperties addObject:@"Discount Value"]; 
     [self.shownProperties addObject:@"Discount Type"]; 
    } 
    else 
    { 
     NSArray* allkeys = [dict allKeys]; 

     NSMutableSet* set = [NSMutableSet setWithArray:allkeys]; 

     NSArray* excludedKeys = @[@"ItemCode", @"id", @"Name", @"createdById", @"jobTypeId", @"createdByFullName", @"publicURL", @"ExpiredOn", @"Quantity", @"In_Stock", @"hrsOfOperation", @"createdOn", 
            @"Image_Name", @"Image_URL", @"Latitude", @"Longitude", @"Attachments", @"Additional_Details", @"jobComments", @"Current_Job_Status,Category_Mall", @"MRP", @"Insights", 
            @"Current_Job_StatusId", @"Next_Seq_Nos", @"CreatedSubJobs", @"Next_Job_Statuses", @"offersCount", @"productsCount", @"businessType", @"storeId", @"CategoryType", @"SubCategoryType", @"P3rdCategory", @"Category_Mall", @"PackageName",@"Current_Job_Status", @"jobTypeName",@"Units", @"guestUserId", @"guestUserEmail", @"Image"]; 

     NSSet* set1 = [NSSet setWithArray:excludedKeys]; 

     [set minusSet:set1]; 

     self.shownProperties = [set allObjects]; 
    } 

    NSMutableArray* excludedKeys = [NSMutableArray array]; 
    for(int index = 0; index < self.shownProperties.count; ++index) 
    { 
     NSString* value = [dict objectForKey:[self.shownProperties objectAtIndex:index]]; 
     if(!value || ![value isKindOfClass:[NSString class]]) 
     { 
      [excludedKeys addObject:[self.shownProperties objectAtIndex:index]]; 
     } 
     if([value isKindOfClass:[NSString class]]) 
     { 
      value = [value stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceAndNewlineCharacterSet]]; 
      if(value.length <= 0) 
      { 
       [excludedKeys addObject:[self.shownProperties objectAtIndex:index]]; 
      } 
     } 

    } 

    NSSet* set1 = [NSSet setWithArray:excludedKeys]; 
    NSMutableSet* set = [NSMutableSet setWithArray:self.shownProperties]; 
    [set minusSet:set1]; 

    self.shownProperties = [set allObjects]; 

    self.tableView.contentInset = UIEdgeInsetsMake(0, 0, 50, 0); 

    [self.tableView reloadData]; 
} 
+0

貴'OnGoProducts'類有一個'Name'財產? – fiddler

+0

嘗試此 _productName.text = [NSString的stringWithFormat:@ 「%@」,_ productInfo.Name]; –

+0

Srija首先你必須檢查你的字典中是否有名字。在此之前,向我展示你得到的迴應。 – user3182143

回答

-1

我覺得例外是由於原因,對象_productInfo是NSDictionary的類型。請調試代碼並檢查_productInfo是否爲NSdictionary類型或OnGoProducts類型。

+0

它是ONGOProducts類型。 – Srija

-1

首先,請解釋這是你在你的代碼一樣productInfo使用你的對象? 如果productInfo是一個字典,那麼你可以得到像_productInfo[@"Name"];這樣的名字。如果不是那麼先告訴我這些物體是什麼。謝謝,希望能幫到你。

+0

這些是ONGOProducts類型 – Srija

+0

你能告訴我你在_productInfo中得到什麼嗎? –

+0

在_productInfo,它示出了產品的細節自我 – Srija

相關問題