2012-03-06 12 views
1

私はUIPickerViewを表示するには2日掛かりましたが、私は迷っています。私は、データソース(NSArray)を接続するためのすべてのメソッドを実装して、なぜそれを表示することができないのか分かりません。今夜は授業が終わり、教授は役に立たないと思っています。私は彼女に尋ねるのをやめました。UIPickerViewは表示されません

これは、UIPickerViewを含むサブビューの.mファイルです。私が必要とするのは、ピッカーが表示されない理由を理解することだけです!ここで

#import "SpotPicker.h" 

@implementation SpotPicker 
@synthesize spotPicker; 

NSArray *pickerLocations; 
NSString *selectedLocation; 

- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil 
{ 
self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil]; 
if (self) { 
    // Custom initialization 
} 
return self; 
} 

- (void)didReceiveMemoryWarning 
{ 
// Releases the view if it doesn't have a superview. 
[super didReceiveMemoryWarning]; 

// Release any cached data, images, etc that aren't in use. 
} 

#pragma mark - View lifecycle 

- (void)viewDidLoad 
{ 
[super viewDidLoad]; 
// Do any additional setup after loading the view from its nib. 
self.modalTransitionStyle=UIModalTransitionStyleFlipHorizontal; 

pickerLocations = [[NSArray alloc]initWithObjects:@"Grand Canyon", @"Mt Rushmore", @"Statue of Liberty", @"Empire State Building", @"Hollywood Sign", @"Lincoln Memorial", @"Space Needle", nil]; 
} 
- (void)viewDidUnload 
{ 
[self setSpotPicker:nil]; 
[super viewDidUnload]; 
// Release any retained subviews of the main view. 
// e.g. self.myOutlet = nil; 
} 

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation 
{ 
// Return YES for supported orientations 
return (interfaceOrientation == UIInterfaceOrientationPortrait); 
} 

- (IBAction)dismissPicker:(id)sender { 
[self dismissModalViewControllerAnimated:YES]; 
} 

- (NSInteger)numberOfComponentsInPickerView:(UIPickerView *)thePickerView { 
return 1; 
} 

- (NSInteger)pickerView:(UIPickerView *)thePickerView numberOfRowsInComponent:(NSInteger)component { 
return [pickerLocations count]; 
} 

- (NSString *)pickerView:(UIPickerView *)thePickerView titleForRow:(NSInteger)row forComponent:(NSInteger)component { 
return [pickerLocations objectAtIndex:row]; 
} 

- (void)pickerView:(UIPickerView *)thePickerView didSelectRow:(NSInteger)row inComponent:(NSInteger)component { 
//NSLog(@"Selected Color: %@. Index of selected color: %i", [pickerLocations objectAtIndex:row], row); 
selectedLocation = [pickerLocations objectAtIndex:row]; 
} 

-(NSString *) getLocation { 
return selectedLocation; 
} 

@end 

はちょうど私が間違って何か愚かな何かを宣言していないことを確認するために、ヘッダファイルです....私は憤慨しています感謝ヘルプ

#import <UIKit/UIKit.h> 

@interface SpotPicker : UIViewController 

- (IBAction)dismissPicker:(id)sender; 
-(NSString *) getLocation; 

@property (weak, nonatomic) IBOutlet UIPickerView *spotPicker; 

@end 

答えて

2

あなたのSpotPickerことを宣言する必要があります実装UIPickerViewDelegateUIPickerViewDataSourceプロトコル:

@interface SpotPicker : UIViewController <UIPickerViewDelegate, UIPickerViewDataSource> 

となるためにあなたのUIPickerViewのデリゲートを設定しますよur SpotPicker。 IBでこれを行うことも、プログラムで行うこともできます。

- (void)viewDidLoad 
{ 
    ... 
    self.spotPicker.delegate = self; 
    self.spotPicker.dataSource = self; 
} 
+0

ユーレカ!ありがとうございました:-Dそれは私が必要なすべてでしたありがとう、ありがとう! – jamzsabb