0

我正在从 sqlite 数据库中获取 TEXT 类型的数据,NSMUtableArray然后我以这种方式将它们分配给 NSString 变量

NSString *billname=[NSString stringWithFormat:@"%@",[tempAyyar valueForkey:@"Bill_Name"]];

但它将值分配为(“测试账单”)。但我想把它作为测试账单。我怎样才能以这种方式获得价值。

谢谢

4

1 回答 1

0

在数组上调用 -valueForKey: 是通过在其对象上调用 -valueForKey: 返回一个带有结果的数组。以下内容来自文档:

Returns an array containing the results of invoking valueForKey: using key on each of the array's objects.

简而言之,您应该检查数组中有哪些对象(可能是 NSDictionary 或类似的东西。)

//just a safety check: if there is at least 1 object
if([tempAyyar count] > 0) {
    //value is probably an NSDictionary (you should check yourself)
    id value = [tempAyyar objectAtIndex:0];

    NSString* billname = [value valueForKey:@"Bill_Name"];

    //now the name Bill's name should show properly
    NSLog(@"Bill's name is %@", billname);
}

也许您需要访问数组中的多个对象,那么您应该调整我提供的示例代码。

于 2012-09-11T11:30:55.397 回答