0

以下に示すような辞書を使用して NSMutableArray を作成する必要があります..方法を教えてください./

(
        {
        businessName = "IBM Business Continuity & Recovery Service";
        city = "Costa Mesa";
        phone = "(714) 668-6900";
        state = CA;
        street = "600 Anton Blvd";
        zip = 92626;
    },
        {
        businessName = "IBM Sanno";
        city = Lomita;
        phone = "(310) 626-0613";
        state = CA;
        street = "25835 Appian Way";
        zip = 90717;
    },
        {
        businessName = "Ewert's IBM Typewriter Service";
        city = "";
        phone = "(559) 732-3215";
        state = "";
        street = "";
        zip = "";
    },
)

ガイドしてください

4

5 に答える 5

3

NSMutableDictionary * list = [[NSMutableDictionary alloc] init];

[list setObject:businessName.text forKey:@"businessName"];
[list setObject:city.text forKey:@"city"];
[list setObject:phone.text forKey:@"phone"];
[list setObject:state.text forKey:@"state"];
[list setObject:street.text forKey:@"street"];
[list setObject:zip.text forKey:@"zip"];

NSMutableArray *listArraySignup = [[NSMutableArray alloc] init];
[listArraySignup addObject:list];
于 2012-12-10T06:29:15.350 に答える
2

辞書が必要な場合NSMutableArrayは、次のようなことができます

NSMutableArray *array = [[NSMutableArray alloc] initWithCapacity: 10];

NSMutableDictionary *dict = [[NSMutableDictionary alloc] initWithCapacity: 10];

[dict setObject: @"IBM Business Continuity & Recovery Service" forKey: @"businessName"];

このように他のオブジェクトを設定します

[array addObject: dict];

[dict release];

このような他の辞書を配列に追加すると、準備完了です:)

于 2012-12-10T06:25:42.397 に答える
1

これを行うには多くの方法があります。

これらの辞書を動的に(大まかに言えば)追加することを計画している場合:

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

NSDictionary *exampleDict = [[NSDictionary alloc] initWithObjectsAndKeys:
@"IBM Business Continuity & Recovery Service", @"businessName", 
@"Costa Mesa", @"city", 
@"(714) 668-6900", @"phone", 
@"CA", @"state", 
@"600 Anton Blvd", @"street", 
@"92626", @"zip", nil];

[dictionaries addObject:exampleDict];
于 2012-12-10T06:21:30.933 に答える
1

新しい Objective-C リテラルを使用

NSArray *array = @[
    @{
        @"businessName" : @"IBM Business Continuity & Recovery Service",
        @"city" : @"Costa Mesa",
        @"phone" : @"(714) 668-6900",
        @"state" : @"CA",
        @"street" : @"600 Anton Blvd",
        @"zip" : @(92626)
    },
    @{
        @"businessName" : @"IBM Sanno",
        @"city" : @"Lomita",
        @"phone" : @"(310) 626-0613",
        @"state" : @"CA",
        @"street" : @"25835 Appian Way",
        @"zip" : @(90717)
    },
    @{
        @"businessName" : @"Ewert's IBM Typewriter Service",
        @"phone" : @"(559) 732-3215"
    }
];
于 2012-12-10T06:38:47.507 に答える
0

これを試して、NSDictionaryを使用してください

于 2012-12-10T06:21:55.850 に答える