0

触れたときに UITextField に UIPickerView を表示させたいと思っています。UITextField.inputView を使用するという同じトピックに関する質問がかなり見つかりました。しかし、試してみても何も変わりません。

私は非常に単純なコードを持っています:

setupViewController.h

#import <UIKit/UIKit.h>

extern NSString *setupRightChannel;

@interface setupViewController : UIViewController
{
    UITextField* rightChannelField; 
    UIPickerView *channelPicker;
}

@property (retain, nonatomic) IBOutlet UITextField* rightChannelField;
@property (retain, readwrite) IBOutlet UIPickerView *channelPicker;

setupViewController.m

#import "setupViewController.h"

@Interface setupViewController()

@end

@implementation setupViewController

@synthesize rightChannelField;

- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
    self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
    if (self) {
        // Custom initialization

    }
    return self;
}


- (void)viewDidLoad
{
    [super viewDidLoad];
    self.navigationItem.title = @"Setup";
    // Do any additional setup after loading the view from its nib.
    rightChannelField.inputView = channelPicker;
}

-(IBAction)okClicked:(id)sender
{
    setupRightChannel = rightChannelField.text;
}

ここで何か根本的なことが抜けているように感じますが、それが何であるかは正直わかりません。

4

1 に答える 1

1
datePicker = [[UIDatePicker alloc]initWithFrame:CGRectMake(0, 250, 325, 300)];
datePicker.datePickerMode =UIDatePickerModeDate;

NSDateFormatter *dateFormatter =[[NSDateFormatter alloc]init];
[dateFormatter setFormatterBehavior:NSDateFormatterBehavior10_4];
[dateFormatter setLocale:[[NSLocale alloc] initWithLocaleIdentifier:@"en_US"]];
[dateFormatter setDateFormat:@"dd MMM yyyy"];

[datePicker addTarget:self action:@selector(dueDateChanged) forControlEvents:UIControlEventValueChanged];

UIToolbar *pickerToolBar =[[UIToolbar alloc]initWithFrame:CGRectMake(0,0, 320,44)];
pickerToolBar.barStyle =UIBarStyleBlackOpaque;
UIBarButtonItem *barButton =[[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemFlexibleSpace target:nil action:nil];
UIBarButtonItem *doneButton =[[UIBarButtonItem alloc] initWithTitle:@"Done"
                                                              style:UIBarButtonItemStyleDone target:self
                                                             action:@selector(closeDueDatePicker:)];
[pickerToolBar setItems:[NSArray arrayWithObjects:barButton, doneButton,nil]];
[self.datePicker addSubview:pickerToolBar];
dueDateTextField.inputView =datePicker; // "This is what changes textfields default responder from keyboard to what ever view you assign it (DatePicker view in this case)." 

ありがとう

于 2012-10-05T03:33:38.313 に答える