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

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

    [self.view addSubview:myPickerView];

最佳答案

实现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来填充数据。希望有帮助!

关于iphone - 如何为UIPickerView设置数据?,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/14542247/

10-09 09:14