UIPickerView程序化的例子? [英] UIPickerView programmatic example?
本文介绍了UIPickerView程序化的例子?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
如何在不使用Interface Builder的情况下以编程方式在视图中设置UIPickerView?也无法理解如何使用UIPickerView的委托部分。
How do I programmatically setup up the UIPickerView in a view without using Interface Builder? Also having trouble understanding how to work with the delegate portions of the UIPickerView.
推荐答案
以编程方式添加UIPickerView:
To add UIPickerView programmatically:
- (void)pickerView:(UIPickerView *)pV didSelectRow:(NSInteger)row inComponent:(NSInteger)component
{
if(component == 1)
selectedRowPicker1 = row;
else if(component == 2)
selectedRowPicker2 = row;
else
selectedRowPicker3 = row;
}
- (NSInteger)numberOfComponentsInPickerView:(UIPickerView *)pickerView
{
return 3;
}
- (NSInteger)pickerView:(UIPickerView *)pickerView numberOfRowsInComponent:(NSInteger)component
{
if(component == 1)
return [list1 count];
else if(component == 2)
return [list2 count];
else
return [list3 count];
}
- (NSString *)pickerView:(UIPickerView *)pickerView titleForRow:(NSInteger)row forComponent:(NSInteger)component
{
if(component == 1)
val1 = [list1 objectAtIndex:row];
else if(component == 2)
val2 = [list2 objectAtIndex:row];
else
val3 = [list3 objectAtIndex:row];
return strTemp;
}
这篇关于UIPickerView程序化的例子?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文