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 に答える