***由于未捕获的异常终止应用程序' NSInvalidArgumentException',原因:' - [__ NSDictionaryM名称]:无法识别的选择器发送到实例

时间:2016-03-10 06:51:41

标签: ios objective-c sqlite

当我在下面调用方法_productName.text = _productInfo.Name时 代码在这里停止并通过断点调试抛出错误。

请指导我......

谢谢!这是我的代码:

-(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];
}

2 个答案:

答案 0 :(得分:-1)

我认为异常是由于对象_productInfo是NSDictionary类型的原因。请调试代码并检查_productInfo是否为NSdictionary类型或OnGoProducts类型。

答案 1 :(得分:-1)

首先请解释您在代码中使用的对象,例如productInfo?。 如果productInfo是字典,那么您可以获得类似_productInfo[@"Name"];的名称。如果它不是那么先告诉我这些对象是什么。谢谢。希望得到这个帮助。