1

私の辞書

    myDictionary = [[publicDataCityArray valueForKey:@"data"] valueForKey:@"name"];

    NSLog(@"myDictionary is %@ myDictionary count is %i",   myDictionary,  [myDictionary count]);

NSLog出力:

myDictionary is (
    Roma,
    Milano,
    Rimini,
    Venezia,
    Firenze,
    Napoli,
    Cesenatico,
    Cervia,
    Recco,
    "Abano Terme",
    "Abbadia Cerreto",
    "Abbadia Lariana",
    "Abbadia San Salvatore",
    Abbasanta,
    Abbateggio,
    Abbiategrasso,
    Abetone,
    Abriola,
    Acate,
    Accadia,
    Acceglio,
    Accettura,
    Acciano,
    Accumoli,
    Acerenza,
    Acerno,
    Acerra,
    "Aci Bonaccorsi",
    "Aci Castello",
    "Aci Catena",
    "Aci Sant'Antonio",
    Acireale,
    Acquacanina,
    Acquafondata,
    Acquaformosa,
    Acquafredda,
    Acqualagna,
    "Acquanegra Cremonese",
    "Acquanegra sul Chiese",
    Acquapendente
) myDictionary count is 40

そして、私はUIActionSheet配列にデータを入力しようとしています:

-(void) someMethod{

    NSError *requestError = nil;

    NSString *savedValue = [[NSUserDefaults standardUserDefaults] stringForKey:@"token"];

    NSString *stringWithToken = [NSString stringWithFormat:@"%@&token=%@",kCityURL, savedValue];

    NSURLRequest *request = [NSURLRequest requestWithURL:[NSURL URLWithString:stringWithToken]];

    NSData *response = [NSURLConnection sendSynchronousRequest:request returningResponse:nil error:&requestError];

    NSError *jsonParsingError = nil;

    if (requestError) {
        NSLog(@"sync. request failed with error: %@", requestError);
    }
    else {
        // handle data
        NSArray *publicDataCityArray =  [NSJSONSerialization JSONObjectWithData:response options:0 error:&jsonParsingError];

        myDictionary = [[publicDataCityArray valueForKey:@"data"] valueForKey:@"name"];

        NSLog(@"myDictionary is %@ myDictionary count is %i",   myDictionary,  [myDictionary count]);

        for (NSDictionary *publicCityDataDict in publicCityDataArray) {

            arrayCitiesActionSheet = [[NSArray alloc] initWithObjects: myDictionary, @"city5", @"city6", @"city7", @"city8",@"city9", @"city10", @"city11", @"city12", @"city13", @"city14", @"city15", @"city16", nil];


           // arrayCitiesActionSheet = [myDictionary allValues];

        }

    }

    UIActionSheet* actionSheet = [[UIActionSheet alloc] init];

    actionSheet.title = @"SELECT A CITY";

    actionSheet.delegate = self;

    for(int i=0;i<[myDictionary count];i++)

    {

        [actionSheet addButtonWithTitle:[arrayCitiesActionSheet objectAtIndex:i]];

    }

    actionSheet.cancelButtonIndex = [actionSheet addButtonWithTitle:@"Cancel"];

    [actionSheet showInView:[UIApplication sharedApplication].keyWindow];

}
4

1 に答える 1

1

myDictionary配列として取ってみましたか、

これを試して 、

 for(int i=0;i<[myDictionary count];i++)
    {
        [actionSheet addButtonWithTitle:[arrayCitiesActionSheet objectAtIndex:i]];
    }

で置き換えます

for(int i=0;i<[myDictionary count];i++)
        {
            [actionSheet addButtonWithTitle:[myDictionary objectAtIndex:i]];
        }
于 2013-09-17T09:36:27.340 に答える