更新! 錯誤是在委託和選擇器視圖:)的DataSource在導航控制器中使用UIPickerView
好吧,這裏的問題是: 我想,我已經創建了一個類「infoGeneral」的視圖來實現一個UIPickerView。
到目前爲止,應用程序的層次結構如下所示:當您單擊「Crear proyecto nuevo」按鈕時,將轉到UiPickerView所在的其他視圖。
App hierarchy(Dropbox的,我不能發表圖片)
我看到如何使用UiPicker視圖的教程,但是在默認視圖。 所以我也跟着教程,但不是使用一些inits在viewDidLoad中,我做這件事是awakeFromNib,(因爲viewDidLoad中是一個視圖控制器的方法,而不是一個視圖一個)
我設置好的了PickerView的數據源和委託,對視圖在哪裏。
但我得到這個錯誤:
2014-12-07 19:11:57.174 calcMuroLosas[6272:182705] -[UIViewController numberOfComponentsInPickerView:]: unrecognized selector sent to instance 0x7fb620c88300
而且我知道錯誤是因爲我使用的是導航控制器。
因此,有人可以告訴我我可以使用該層次結構中的pickerview嗎?
這裏是我的文件:
infoGeneral.h
#import <UIKit/UIKit.h>
@interface infoGeneral : UIView <UIPickerViewDelegate, UIPickerViewDataSource>
@property (retain, nonatomic) IBOutlet UIPickerView *picker;
- (IBAction)buttonPressed:(id)sender;
@end
infoGeneral.m
#import "infoGeneral.h"
@interface infoGeneral()
@property (strong, nonatomic) NSArray *arrayTipoCodigoEsfuerzosAdmisibles;
@end
@implementation infoGeneral
/*
// Only override drawRect: if you perform custom drawing.
// An empty implementation adversely affects performance during animation.
- (void)drawRect:(CGRect)rect {
// Drawing code
}
*/
- (void)awakeFromNib
{
NSArray *dataTipoCodigoEsfuerzosAdmisibles = [[NSArray alloc] initWithObjects:@"MSJC", @"Guatemala", @"El Salvador", @"Honduras", @"Nicaragua", @"Costa Rica", @"Panamá (MSJC)", @"México", @"Chile", @"Colombia", @"Canada", @"Perú", @"Dominicada (similar a MSJC)", @"Ecuador", @"Otro", nil];
self.arrayTipoCodigoEsfuerzosAdmisibles = dataTipoCodigoEsfuerzosAdmisibles;
}
- (IBAction)buttonPressed:(id)sender {
NSString *select = [_arrayTipoCodigoEsfuerzosAdmisibles objectAtIndex:[_picker selectedRowInComponent:0]];
NSString *title = [[NSString alloc]initWithFormat:@"You selected %@!", select];
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:title message:@"YAY!" delegate:nil cancelButtonTitle:@"OK" otherButtonTitles: nil];
[alert show];
}
#pragma mark Picker Data Sources Methods
-(NSInteger)numberOfComponentsInPickerView:(UIPickerView *)pickerView
{
return 1;
}
-(NSInteger)pickerView:(UIPickerView *)pickerView numberOfRowsInComponent:(NSInteger)component
{
return [_arrayTipoCodigoEsfuerzosAdmisibles count];
}
#pragma mark Picker Delegate Methods
-(NSString *)pickerView:(UIPickerView *)pickerView titleForRow:(NSInteger)row forComponent:(NSInteger)component
{
return [_arrayTipoCodigoEsfuerzosAdmisibles objectAtIndex:row];
}
@end
你是否勾起了選擇器視圖讓文件所有者成爲委託? – kpsharp 2014-12-08 02:32:39
是的,我已經做到了 – 2014-12-08 05:39:15
我發現錯誤! <3 <3 <3 代表是「Informacion General」(導航欄的名稱)我不知道爲什麼,大豆我檢查了選取器的出口檢查員並注意到了這一點。所以我把它改爲「信息一般」(名稱os .h和.m文件,它的工作!謝謝你:) – 2014-12-08 05:47:48