データ型の Web サービスから成功した結果が得られましたが、コンテンツの結果をオブジェクトNSMutableArray
に表示するにはどうすればよいかというジレンマがあります。UIPickerView
これを実行したとき、 には何も表示されませんでしUIPickerView
たが、ボタンをクリックすると、Web サービス コンテンツから最初の国がポップされました。コメントをいただければ幸いです。ここに私のコードがあります。
myViewController.h
#import <UIKit/UIKit.h>
#import "Service.h"
@class myController;
@interface PromoViewController : UIViewController <UIPickerViewDataSource, UIPickerViewDelegate, UIPickerViewDelegate>{
}
@property (strong, nonatomic) IBOutlet UIPickerView *singlePicker;
@property (strong, nonatomic) NSArray *pickerData;
- (IBAction)buttonPressed;
@end
=======================
myViewController.m:
#import "myViewController.h"
#import "Service.h"
@implementation myViewController;
@synthesize singlePicker;
@synthesize pickerData;
- (IBAction)buttonPressed {
NSInteger row = [singlePicker selectedRowInComponent:0];
NSString *selected = [pickerData objectAtIndex:row];
NSString *title = [[NSString alloc] initWithFormat:
@"You selected %@!", selected];
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:title
message:@"Thank you for choosing."
delegate:nil
cancelButtonTitle:@"You're Welcome"
otherButtonTitles:nil];
[alert show];
}
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
if (self) {
// Custom initialization
}
return self;
}
- (void)didReceiveMemoryWarning
{
[super didReceiveMemoryWarning];
}
#pragma mark - View lifecycle
- (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view from its nib.
//NSArray *array = [[NSArray alloc] initWithObjects:@"Luke", @"Leia",
// @"Han", @"Chewbacca", @"Artoo", @"Threepio", @"Lando", nil];
//self.pickerData = array;
Service* service = [[Service alloc] init];
[service WEBServiceCountries:self action:@selector(handleAllCountries:)];
//self.pickerData = countryArray;
}
-(NSMutableArray *) handleAllCountries:(id) value{
NSMutableArray *a = value;
NSLog(@"myViewController: we have %d countries", [a count]);
NSMutableArray *countryArray = [[NSMutableArray alloc] init];
NSMutableArray *countryArrayid = [[NSMutableArray alloc] init];
for (LBCCountry *country in a ){
NSLog(@"myViewController: %d - %@", country.CountryID, country.CountryName);
[countryArray addObject:country.CountryName];
[countryArrayid addObject:[NSString stringWithFormat:@"%d",country.CountryID]];
}
self.pickerData = countryArray;
NSLog(@"pickerData: %@", pickerData);
return countryArray;
}
- (void)viewDidUnload
{
[super viewDidUnload];
self.singlePicker = nil;
self.pickerData = nil;
}
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
return (interfaceOrientation == UIInterfaceOrientationPortrait);
}
#pragma mark -
#pragma mark Picker Data Source Methods
- (NSInteger)numberOfComponentsInPickerView:(UIPickerView *)pickerView {
return 1;
}
- (NSInteger)pickerView:(UIPickerView *)pickerView
numberOfRowsInComponent:(NSInteger)component {
return [pickerData count];
}
#pragma mark Picker Delegate Methods
- (NSString *)pickerView:(UIPickerView *)pickerView
titleForRow:(NSInteger)row
forComponent:(NSInteger)component {
return [pickerData objectAtIndex:row];
}
@end
==============