my dictionary
myDictionary = [[publicDataCityArray valueForKey:@"data"] valueForKey:@"name"];
NSLog(@"myDictionary is %@ myDictionary count is %i", myDictionary, [myDictionary count]);
NSLog
output:
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
and I'm trying to populate the UIActionSheet
array:
-(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];
}