3

我正在尝试添加 PickerView - 但我看到黑屏......我做错了什么???

UIPickerView *myPickerView = [[UIPickerView alloc] initWithFrame:CGRectMake(0, 0, 320, 320)];

    [self.view addSubview:myPickerView];
4

1 回答 1

5

实现UIPickerViewDataSource方法:

– numberOfComponentsInPickerView:
– pickerView:numberOfRowsInComponent:

UIPickerViewDelegate方法:

– pickerView:titleForRow:forComponent:

不要忘记设置属性:

UIPickerView * myPickerView = [[UIPickerView alloc] initWithFrame:CGRectMake(0, 0, 320, 320)];
myPickerView.delegate = self;
myPickerView.dataSource = self;
[self.view addSubview:myPickerView];

在 .h 文件中,记得放:

<UIPickerViewDelegate, UIPickerViewDataSource>

我通常使用NSMutableArray填充字符串来填充数据。希望有帮助!

于 2013-01-26T22:45:09.807 回答