我的字典
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];
}
答案 0 :(得分: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]];
}