使用 uitextfield 字符串实例化 UIPicker

发布于 2024-11-19 16:48:33 字数 386 浏览 2 评论 0原文

我试图将我的 UItextfield 值传递给我在警报视图中加载的 UIPicker 我只是不确定可以使用哪些功能将值返回到选择器中?

猜测我应该在我的中做一些事情,

- (NSInteger)pickerView:(UIPickerView*)pv numberOfRowsInComponent:(NSInteger)component
{
    if (pv == pickerViewA) {
        return 10;
    }
    else
        return 16;
}

但查看开发人员注意到,除了返回行数之外,他们没有太多关于 UIPickerViewDataSource 的信息......

任何帮助将不胜感激。

I am trying to pass my UItextfield value over to a UIPicker that I have loading in a alertview I'm just not sure what functions are available to me to get the values back into the picker?

At a guess I should be doing something in my

- (NSInteger)pickerView:(UIPickerView*)pv numberOfRowsInComponent:(NSInteger)component
{
    if (pv == pickerViewA) {
        return 10;
    }
    else
        return 16;
}

but looking at the developers notes their is not much info about the UIPickerViewDataSource other than returning number of rows...

any help would be greatly appreciated.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

我很OK 2024-11-26 16:48:33

还有其他数据源和代表 - 有关

//for title of a row in a component
- (NSString *)pickerView:(UIPickerView *)pickerView titleForRow:(NSInteger)row forComponent:(NSInteger)component

//for width of a componenet
- (CGFloat)pickerView:(UIPickerView *)pickerView widthForComponent:(NSInteger)component

//for row height of a component
-(CGFloat)pickerView:(UIPickerView *)pickerView rowHeightForComponent:(NSInteger)component

//for number of components 
-(NSInteger)numberOfComponentsInPickerView:(UIPickerView *)pickerView

更多信息,请参阅文档 -
http://developer.apple.com/library/ios/#DOCUMENTATION/UIKit/Reference/UIPickerViewDelegate_Protocol/Reference/UIPickerViewDelegate.html

http://developer.apple.com/library/ios/#documentation/uikit/reference/UIPickerView_Class/Reference/UIPickerView.html

There are other data source and delegates as-

//for title of a row in a component
- (NSString *)pickerView:(UIPickerView *)pickerView titleForRow:(NSInteger)row forComponent:(NSInteger)component

//for width of a componenet
- (CGFloat)pickerView:(UIPickerView *)pickerView widthForComponent:(NSInteger)component

//for row height of a component
-(CGFloat)pickerView:(UIPickerView *)pickerView rowHeightForComponent:(NSInteger)component

//for number of components 
-(NSInteger)numberOfComponentsInPickerView:(UIPickerView *)pickerView

for more info look at documentation -
http://developer.apple.com/library/ios/#DOCUMENTATION/UIKit/Reference/UIPickerViewDelegate_Protocol/Reference/UIPickerViewDelegate.html

and

http://developer.apple.com/library/ios/#documentation/uikit/reference/UIPickerView_Class/Reference/UIPickerView.html

孤芳又自赏 2024-11-26 16:48:33

您可以使用以下两个委托之一向 UIPickerView 添加数据内容

– pickerView:titleForRow:forComponent:

– pickerView:viewForRow:forComponent:reusingView:

对于第一个委托,您可以返回任何 NSString 对象,并且不能自定义字体大小等任何内容或颜色。
但是,如果您使用第二个,您可以将数据内容作为视图添加到 UIPickerView,这可以使用 UILabel 来实现,在这里您可以根据需要自定义视图。

希望这可以帮助您

快乐编码!

You can use either one of the following two delegates to add data content to UIPickerView

– pickerView:titleForRow:forComponent:

– pickerView:viewForRow:forComponent:reusingView:

For the first one u can return any NSString object and you cannot customize anything like font size or color for that.
But if you use the second one you can add the data content as a view to UIPickerView which can be achieved using a UILabel and here you can customize the view as you require.

Hope this might help you

Happy coding !

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文