gpt4 book ai didi

ios/xcode/objective-c : UIPickerView Not Displaying

转载 作者:行者123 更新时间:2023-11-28 19:45:19 25 4
gpt4 key购买 nike

我有一个 UIPickerView 显示在 Storyboard中,但如果我在编译程序时更改背景颜色,它是不可见的或充其量是一个彩色 block 。我是否需要用数据填充它才能显示,即编译后是否不再显示 Cupertino、Mountain View 等?

顺便说一句,我正在尝试用数据填充选择器 View 但仍然不可见:

    code:
in .h file:
@interface pickerVC : UIViewController<UIPickerViewDelegate,UIPickerViewDataSource>
@property (weak, nonatomic) IBOutlet UIPickerView *pickerView;
@property (strong, nonatomic) IBOutlet UILabel *color;
@property (strong, nonatomic) NSArray *myArray;

in viewdidload;
UIPickerView *pickerView;
pickerView.delegate = self;
_myArray = [[NSArray alloc] initWithObjects:@"Blue",@"Green",@"Orange",@"Purple",@"Red",@"Yellow" , nil];


//PICKER METHODS
// tell the picker how many rows are available for a given component
- (NSInteger)pickerView:(UIPickerView *)pickerView numberOfRowsInComponent:(NSInteger)component {
// NSUInteger numRows = 3;

return _myArray.count;
}

// tell the picker how many components it will have
- (NSInteger)numberOfComponentsInPickerView:(UIPickerView *)pickerView {
return 1;
}

// tell the picker the title for a given component
- (NSString *)pickerView:(UIPickerView *)pickerView titleForRow:(NSInteger)row forComponent:(NSInteger)component {
NSString *title;

title = _myArray[row];

return title;
}

// tell the picker the width of each row for a given component
- (CGFloat)pickerView:(UIPickerView *)pickerView widthForComponent:(NSInteger)component {
int sectionWidth = 300;

return sectionWidth;
}
- (void)pickerView:(UIPickerView *)pickerView didSelectRow: (NSInteger)row inComponent:(NSInteger)component{
NSLog(@"Selected Row %d", row);
switch(row){
// Handle the selection
}

最佳答案

是的,您需要实现数据源和选择器 View 委托(delegate)。

关于ios/xcode/objective-c : UIPickerView Not Displaying,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32585175/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com