简体   繁体   English

工作几天后,UITextField.inputView突然不弹出UIPickerView

[英]UITextField.inputView suddenly not popping up UIPickerView after working for days

I'm working on my first app ever (quite a learning experience). 我正在开发我的第一个应用程序(颇有学习经验)。 Today after studying and reading and trial/error I was able to programmatically create and fill a UIPickerView and have it pop up when I select the appropriate UITextField. 今天,在学习,阅读和尝试/错误之后,我能够以编程方式创建和填充UIPickerView,并在选择适当的UITextField时将其弹出。

I have my main ViewController with a UITableView already setup and populated with some JSON data. 我的主ViewController已经设置了UITableView并填充了一些JSON数据。 Above the UITableView I added a subview (called FilterView below) I want to house some controls to filter my UITableView (I'm not so sure the subview isn't part of the problem). 我在UITableView上方添加了一个子视图(以下称为FilterView ),我想容纳一些控件来过滤我的UITableView (我不确定该子视图不是问题的一部分)。 After creating my UIPickerView in code (didn't use Storyboard) and filling it with some data, and setting my UITextField in my subview with the appropriate .inputView (to trigger the UIPickerView to appear) I had everything working the way I wanted and was about to move on to setting precedents for filtering my `UITableView. 在用代码创建UIPickerView (不使用Storyboard)并填充一些数据,并在子视图中使用适当的.inputView设置UITextField (触发UIPickerView出现)后,我便可以按照我想要的方式进行所有工作即将设置过滤我的UITableView的先例。

So here is my layout of my views with textfields in storyboard: 这是我在情节提要中带有文本字段的视图布局: 在此处输入图片说明

You'll notice I have my main view (called View ), a subview with all my controls in it (called FilterView ), and my UITableView below all that. 您会注意到我有我的主视图(称为View ),一个包含所有控件的子视图(称为FilterView )以及所有这些下面的UITableView Then I created my three picker UIPickerViews in my viewDidLoad , set the DataSource and Delegate and set the inputView to the textfields I wanted: 然后,我在viewDidLoad创建了三个选择器UIPickerViews ,设置了DataSource和Delegate,并将inputView设置为所需的文本字段:

_voltagePickerView =    [[UIPickerView alloc] initWithFrame:CGRectZero];
[_voltagePickerView setDataSource: self];
[_voltagePickerView setDelegate: self];
_voltagePickerView.showsSelectionIndicator = YES;
_voltageFilterField.inputView = _voltagePickerView;

//same for other 3

And of course the UIPickerView properties are in my ViewController.h file, along with the Outlets for the UITextField s: 当然,UIPickerView属性和UITextField的Outlets都在我的ViewController.h文件中:

@property (strong, nonatomic) UIPickerView *rpmPickerView;
@property (strong, nonatomic) UIPickerView *voltagePickerView;
@property (strong, nonatomic) UIPickerView *noiseLevelPickerView;

@property (strong, nonatomic) IBOutlet UITextField *voltageFilterField;
@property (strong, nonatomic) IBOutlet UITextField *rpmFilterField;
@property (strong, nonatomic) IBOutlet UITextField *noiseLevelFilterField;

All the methods for the PickerView are also setup: 还设置了PickerView的所有方法:

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

-(NSInteger)pickerView:(UIPickerView *)pickerView numberOfRowsInComponent:(NSInteger)component {
    if ([pickerView isEqual: _voltagePickerView]) {
        return voltagePickerValues.count;
    }
    else if () {
        //Rest of PickerView rows
    }
    else {
        return 0;
    }

}

-(NSString *)pickerView:(UIPickerView *)pickerView titleForRow:(NSInteger)row forComponent:(NSInteger)component {

    NSString *title;

    if ([pickerView isEqual: _voltagePickerView]) {
        title = [voltagePickerValues objectAtIndex:row];
    }
    else if {
        //Rest of Picker Views
    }

    else {
        title = nil;
    }

    return title;

}

All of this would work fine! 所有这些都可以正常工作! I would run the project, TableView would populate, and I could click on the appropriate TextField in order to show the appropriate PickerView with the correct data populated into them. 我将运行该项目,将填充TableView,然后单击适当的TextField,以显示具有正确数据的适当PickerView。

Then... The only thing I changed (that I can think of) was changing the PlaceHolderText property of one of my UITextFields... that's it, I may have also lined up the TextFields to look better. 然后...我唯一能改变的(我能想到的)就是更改我的UITextFields的PlaceHolderText属性...就是这样,我可能还排好了TextField的外观。 Then I ran the project and the Pickers would not show when I clicked on a TextField. 然后,我运行了该项目,当我单击TextField时,选择器将不会显示。 I checked the Outlets for the TextViews and PickerFields, all the same. 我检查了Outlet的TextViews和PickerFields,都一样。 I even deleted the Reference Outlets for the TextViews and recreated them. 我什至删除了TextViews的参考插座,然后重新创建了它们。 Nothing. 没有。

I honestly have no clue what happened. 老实说,我不知道发生了什么事。 Everything is exactly the same way as it was before with the exception of the PlaceHolderText property of one of the UITextFields . 除了UITextFields之一的PlaceHolderText属性外,其他所有操作都与以前完全相同。

I've cleaned and rebuilt my project, restarted xcode and even my mac, but nothing. 我已经清理并重建了项目,重新启动了xcode,甚至重新启动了mac,但是什么也没有。

What am I missing?? 我想念什么? Sorry for the lengthy post, and thanks so much if you made it this far. 抱歉,冗长的帖子,如果您到目前为止做的很感谢。

I ran your code with dummy titles and it worked for me. 我用伪标题运行了您的代码,它对我有用。

One thing that I added that was missing from your code excerpts was: 我添加的一件事是您的代码摘录中缺少的一件事是:

[self.view addSubview:_voltagePickerView];

where self is the view controller. self是视图控制器。

Instead of deleting I thought I'd answer in hopes it will help others. 我没有删除我想回答的内容,希望对其他人有帮助。

I had to change the hardware settings in the simulator. 我必须在模拟器中更改硬件设置。 I don't know why but the simulator seems to be bugged. 我不知道为什么,但是模拟器似乎有问题。

Unchecking Hardware => Keyboard => Connect Hardware Keyboard in the simulator fixed the problem. 取消选中Hardware => Keyboard => Connect Hardware Keyboard模拟器中的Hardware => Keyboard => Connect Hardware Keyboard可解决此问题。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM