我希望 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;
}
我觉得我可能在这里遗漏了一些基本的东西,但老实说,我想不出它是什么。