UIPickerView程序示例? [英] UIPickerView programatic example?

查看:104
本文介绍了UIPickerView程序示例?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何以编程方式在不使用Interface Builder的情况下在视图中设置UIPickerView?



感谢

解决方案

如下以编程方式添加UIPickerView:

   - (void)pickerView: )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 = 1)
val1 = [list1 objectAtIndex:row];
else if(component == 2)
val2 = [list2 objectAtIndex:row];
else
val3 = [list3 objectAtIndex:row];

return strTemp;
}

如果在此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.

Thanks

解决方案

It will goes like as follows 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;
}

Let me know if you have any questions in this UIPickerView implementation.

这篇关于UIPickerView程序示例?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆