我正在尝试UIActionSheet
使用来自NSArray
. 我有 cityTitleNodeArray 这是一个NSArray
(nslog
下面的输出)。目前它只显示第一个项目NSArray
作为第一个按钮UIActionSheet
我希望它看起来像这样(除了数组信息都应该来自 cityTitleNodeArray):
NSArray *array = [[NSArray alloc] initWithObjects: cityTitleNodeArray, @"city2", @"city3", @"city4", @"city5", @"city6", @"city7", @"city8",@"city9", @"city10", @"city11", @"city12", @"city13", @"city14", @"city15", @"city16", nil];
UIActionSheet *actionSheet = [[UIActionSheet alloc] initWithTitle:@"Title Here"
delegate:self
cancelButtonTitle:nil
destructiveButtonTitle:nil
otherButtonTitles:nil];
for (NSString *title in array) {
[actionSheet addButtonWithTitle:title];
}
[actionSheet addButtonWithTitle:@"Cancel"];
actionSheet.cancelButtonIndex = [array count];
[actionSheet showInView:self.view];
-(void)requestCityData {
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
NSDictionary *publicData = [NSJSONSerialization JSONObjectWithData:response options:0 error:&jsonParsingError];
publicCityDataArray = [publicData objectForKey:@"data"];
for (NSDictionary *publicCityDataDict in publicCityDataArray) {
cityTitleNodeArray = [publicCityDataDict objectForKey:@"name"];
NSLog(@"cityTitleNodeArray from requestCityData output is %@",cityTitleNodeArray);
}
}
}
cityTitleNodeArray
输出是:
`cityTitleNodeArray` from `requestCityData` output is Roma
2013-09-16 12:49:28.001 1000 [3980:907] cityTitleNodeArray from requestCityData output is Milano
2013-09-16 12:49:28.002 1000 [3980:907] cityTitleNodeArray from requestCityData output is Rimini
2013-09-16 12:49:28.002 1000 [3980:907] cityTitleNodeArray from requestCityData output is Venezia
2013-09-16 12:49:28.003 1000 [3980:907] cityTitleNodeArray from requestCityData output is Firenze
2013-09-16 12:49:28.003 1000 [3980:907] cityTitleNodeArray from requestCityData output is Napoli