iOS:价值不是以字符串形式出现的?

时间:2014-06-25 00:46:08

标签: ios objective-c

在我的代码中,我将数组设置在NSMutableDictionary内作为

if (array.count > 0) {
            [self.filters setValue:array forKey:[self getKey:[[NSNumber numberWithInt:indexPath.section] intValue]]];
        }

其中array

NSMutableArray *array = [[NSMutableArray alloc] init];

当接收代码收到它时,我试图将数组中的值加入

if ([item objectForKey:@"category_filter"] != nil) {
        NSArray *array = [NSArray arrayWithObjects:[item objectForKey:@"category_filter"], nil];
        NSString *categories = [array componentsJoinedByString:@","];

        NSLog(@"value:%@", categories);
    }

其中item(NSMutableDictionary *)item

当我看到日志时,我看到

2014-06-24 17:43:12.520 yelp[69744:70b] value:(
    "Bagels (bagels)",
    "Bakeries (bakeries)"
)

所以他们还没有加入。我在这里做错了什么?

1 个答案:

答案 0 :(得分:1)

作为Hot Licks commented

我必须做出改变

NSArray *array = [NSArray arrayWithArray:[item objectForKey:@"category_filter"]];  

而不是

NSArray *array = [NSArray arrayWithObjects:[item objectForKey:@"category_filter"]];