UIViewController中的iPhone UIPickerView [英] iPhone UIPickerView in UIViewController

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

问题描述

我有一个xib,其中添加了一个名为delta的 UIViewController .delta下的视图由delta viewcontroller而不是文件所有者控制.在增量视图上,我有一个 UIViewPicker .我的问题是我正在使用 deltaviewcontroller 中的 UIPickerView 进行编程,并且我将 deltaviewcontroller 发行为的委托和数据源.> UIPickerView .一切正常,但是当我加载deltaviewcontroller的视图时,应用程序崩溃.如果我在文件所有者视图下以相同的方式执行所有操作,则可以正常工作.我想知道是否真的有一种方法可以使UIPickerView与 UIViewController 一起工作,而不一定与文件的所有者一起工作.

I have a xib in which I have added a UIViewController named delta. The view under delta is controlled by the delta viewcontroller, not the file owner. On the delta view, I have a UIViewPicker. My issue is that I am programming in the UIPickerView in the deltaviewcontroller and I'm issuing deltaviewcontroller as the delegate and data source for the UIPickerView. Everything should work, but when I load the deltaviewcontroller's view, the application crashes. If I carry out everything the same way under the file's owner view, it works fine. I'm wondering if there is really a way to make the UIPickerView work with a UIViewController and no necessarily a file's owner.

有关参考,代码:

标题

@interface DeltaViewController : UIViewController <UIPickerViewDelegate, UIPickerViewDataSource> {
    NSMutableArray *arrayNo;
    IBOutlet UIPickerView *pickerView;
}
@property (nonatomic, retain) UIPickerView *pickerView;
@property (nonatomic, retain) NSMutableArray *arrayNo;

@end

实施

#import "DeltaViewController.h"

@implementation DeltaViewController

@synthesize pickerView;
@synthesize arrayNo;

- (void)viewDidLoad
{
    NSMutableArray *dollarsArray = [[NSMutableArray alloc] init];

    for (int i = 0; i < 100; i++)
    {
        NSString *item = [[NSString alloc] initWithFormat:@"%i", i];
        [dollarsArray addObject:item];
    }

    self.arrayNo = dollarsArray;

    [dollarsArray release]; 
}

#pragma mark -
#pragma mark Picker Data Source Methods

- (NSInteger)numberOfComponentsInPickerView:(UIPickerView *)pickerView
{
    return 1;
}

- (NSInteger)pickerView:(UIPickerView *)pickerView numberOfRowsInComponent:(NSInteger)component
{
    return [arrayNo count];
}

#pragma mark Picker Delegate Methods

- (NSString *)pickerView:(UIPickerView *)pickerView titleForRow:(NSInteger)row forComponent:(NSInteger)component
{
    return [arrayNo objectAtIndex:row];
}

- (void)dealloc {
    [arrayNo release];
    [pickerView release];
    [super dealloc];
}

@end

请指出我是否做错了什么.非常感谢您的帮助.

Please point out if I'm doing anything wrong. Help is much appreciated.

推荐答案

如果您搜索如何在UIView中添加UIPickerView,只需签出Apple示例代码以获取UIPickerView.我认为这是学习正确使用不同类的最佳方法之一.有五个项目,其中包括一个UIPickerView.这是链接

If you search how to add a UIPickerView in a UIView, just check out the Apple sample code for UIPickerView. I think it's one of the best ways learning to use the different classes correctly. There are five project which includes an UIPickerView. Here's the link

UIPickerView类参考和示例代码

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

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