我正在尝试添加PickerView - 但我看到一个黑屏......我做错了什么???
UIPickerView *myPickerView = [[UIPickerView alloc] initWithFrame:CGRectMake(0, 0, 320, 320)];
[self.view addSubview:myPickerView];
答案 0 :(得分:5)
– numberOfComponentsInPickerView:
– pickerView:numberOfRowsInComponent:
– 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
来填写数据。希望有所帮助!