0

代码:

[self.menuList addObject:[NSDictionary dictionaryWithObjectsAndKeys:
                                       NSLocalizedString(@"PropertySubtype2fTitle", @""), 
                                       kTitleKey,
                                       publishNoOfRoomsViewController, 
                                       kViewControllerKey, nil]];

menuList 是一个 NSMutableArray。

我想稍后在代码中读取 PropertySubtype2fTitle 本地化字符串,例如:

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
4

2 回答 2

8

要从 NSDictionary 中获取条目,您可以使用

[NSDictionary objectForKey:(id)keyValue]
. 要从 NSArray / NSMutableArray 中获取条目,您可以使用
[NSArray objectAtIndex:(NSUInteger)index]
. 结合并应用于您的示例,应该是:
NSString *title = [[menuList objectAtIndex:index] objectForKey:kTitleKey];
而 index 将是一个无符号整数(NSUInteger)。

于 2010-02-26T00:30:06.580 回答
0

为什么不直接使用NSMutableDictionary

例如:

NSData *getData = [[NSData alloc] initWithContentsOfURL:[NSURL URLWithString:strURL]];
NSError *errorData;
NSMutableDictionary *dicData = [NSJSONSerialization
                                     JSONObjectWithData:getData
                                     options:NSJSONReadingMutableContainers
                                     error:&errorData];

if( errorData )
{
    NSLog(@"%@", [errorData localizedDescription]);
}
else {

    NSString *title =   [[dicData[@"items"] objectAtIndex:1] objectForKey:@"titlekey"];
    NSLog(@"titlekey %@",title);
}
于 2013-12-29T09:49:09.840 回答