我試圖做單組分選擇器例如開始的iOS 6發展的圖書,幾乎每一件事工作正常,但數據從數組沒有出現在pickerView 請幫助數據沒有顯示在pickerView
了這裏是我的.h文件
<UIPickerViewDataSource , UIPickerViewDelegate>
{
IBOutlet UIPickerView *singlePicker;
NSArray *chaNames;
}
@property (strong, nonatomic) IBOutlet UIPickerView *singlePicker;
@property (strong, nonatomic) NSArray *chaNames;
- (IBAction)buttonPressed:(id)sender;
@end
這裏是.m文件
#import "SSPSingleComponentViewController.h"
@interface SSPSingleComponentViewController()
@end
@implementation SSPSingleComponentViewController
- (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view from its nib.
self.chaNames = @[@"Luke",@"Leia",@"Han",@"Chewbacca",@"Artoo", @"Threepio",@"lando"];
}
- (IBAction)buttonPressed:(id)sender {
NSInteger row = [self.singlePicker selectedRowInComponent:0];
NSString *selected = self.chaNames[row];
NSString *title = [[NSString alloc]initWithFormat:@"You slected %@", selected];
UIAlertView *alert = [[UIAlertView alloc]initWithTitle:@"OutPut is : " message:title delegate:self cancelButtonTitle:@"OK" otherButtonTitles:nil, nil];
[alert show];
}
-(NSInteger)numberOfComponentsInPickerView:(UIPickerView *)pickerView
{
return 1;
}
-(NSInteger)pickerView:(UIPickerView *)pickerView
numberOfRowsInComponent:(NSInteger)component
{
return [self.chaNames count];
}
-(NSString *)pickerView:(UIPickerView *)pickerView
titleForRow:(NSInteger)row
forComponent:(NSInteger)component
{
return[self.chaNames objectAtIndex:row];
}
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
if (self) {
// Custom initialization
}
return self;
}
- (void)didReceiveMemoryWarning
{
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
@end
請幫助提前 感謝:)
是選擇器視圖的數據源,並在所有被稱爲委託方法正確地把它掛?確保你設置了選擇器視圖的'dataSource'和'delegate'屬性。 – rmaddy 2013-03-10 17:59:06
嗨, 我設置了選擇器視圖的dataSource和委託屬性,但仍然不起作用 – Happy 2013-03-10 18:03:54
正如我第一次問,數據源和委託方法是否被調用?在'numberOfComponentsInPickerView'中設置一個斷點或者添加一個'NSLog'。 – rmaddy 2013-03-10 18:05:08