我已经对这个话题进行了深入研究,发现人们在许多网站上发布了完全相同的问题,包括 right here在计算器中。
我已经尝试了所有的建议,但无法让 UIDatePicker 实际显示。我采取什么方法似乎并不重要。我已经尝试使用继承模型,在其中我将 UITextBox 控件子类化并覆盖它的默认方法以显示 UIDatePicker 然后我确保在 StoryBoard 中我将我的 UITextView 控件的类设置为该自定义类。我已经尝试以编程方式生成 UIDatePicker,还尝试将它拖到 StoryBoard 中的 View 上。当我尝试编程方法时,什么也没有显示,当我尝试将它拖到 StoryBoard 上时,它总是显示。当我将它的属性设置为“隐藏”时,它会隐藏,但即使我尝试向应该取消隐藏它的 textboxDidBeginEditing 方法添加代码,我也无法显示它。
我已确保将 UITextView 的 inputView 属性设置为等于我的 UIDatePicker 控件。
没有任何作用!我不明白为什么 Apple 不只是将 UIDatePicker 作为 UITextView 控件的属性检查器下拉列表中的默认选项之一。这会让这件事变得容易得多。
下面是我的实现类文件中的一些代码。
#import "AddTasksViewController.h"
@implementation AddTasksViewController
@synthesize dueDate;
@synthesize description;
@synthesize shortTitle;
@synthesize datePicker;
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
if (self) {
// Custom initialization
self.dueDate.inputView = datePicker;
}
return self;
}
- (IBAction)dueDateDidBeginEditing:(UITextView *)textField
{
[textField resignFirstResponder];
[datePicker setFrame:CGRectMake(0,200,320,120)];
[datePicker addTarget:self action:@selector(done) forControlEvents:UIControlEventValueChanged];
[self.view addSubview:datePicker];
}
这是我的头文件的样子...
#import <UIKit/UIKit.h>
@interface AddTasksViewController : UIViewController
@property (nonatomic, copy) IBOutlet UITextView *dueDate;
@property (nonatomic, copy) IBOutlet UITextView *description;
@property (nonatomic, copy) IBOutlet UITextView *shortTitle;
@property (nonatomic, retain) IBOutlet UIDatePicker *datePicker;
- (IBAction)doneEditing:(id)sender;
- (IBAction)dateChanged:(id)sender;
- (IBAction)dueDateDidBeginEditing:(UITextView *)textField;
@end
正如我已经提到的,我采用的其他方法(即子类化 UITextView)也没有用。我复制了提供的代码 here正如它所显示的那样。然后我将名为“DateField”的自定义类添加到我的项目(头文件和实现文件),然后在我的 AddTaskViewController.h 和 AddTaskViewController.m 文件中用 DateField 替换了 dueDate 的 UITextBox 声明,并确保 StoryBoard 引用通过在 Identity Inspector 中为控件的类选择 DateField 更新为。
无论我做什么,我都无法在单击 UITextView 时显示 UIDatePicker。当我设置断点时,它确实触发了 dueDateDidBeginEditing 方法,所以我知道正在触发某些事情。问题是我不明白为什么没有使用 UIDatePicker 显示 subview 。
任何帮助将不胜感激,因为这个看似简单的任务似乎比它应该花费的时间要长得多。在 Java 和 C# 中,我可以闭着眼睛双手绑在背后做这类事情,但是当涉及到 Objective-C 时,一切都变得不必要地复杂。语法真的让我恼火。
这么多方括号!!!啊!!!
最佳答案
为 UITextField 的 inputView 显示 UIDatePicker 与显示键盘相比相对困难,但与您的麻烦相比相对容易有过。
我在您的代码中注意到的第一个问题是您试图设置一个尚不存在的对象的属性,这对于 iOS/Mac 开发的新手来说是一个非常普遍的问题。将“self.dueDate.inputView = datePicker;”放入您的 initWithNibName:bundle: 将不起作用,因为 View 尚未加载,并且 dueDate 是您 View 的一部分。在 objective-c 中,对象是用 alloc & init 实例化的。 Init 是对任何对象的第一个真正的方法调用。此时在你的 View Controller 的生命中, View 还没有被创建。 self.dueDate.inputView = datePicker;所属的方法调用在viewDidLoad方法中。它在听起来像是被调用的时候被准确地调用,并且你的 dueDate 属性将在那个时候被正确加载。无需使用 UITextField 的自定义子类来显示文本字段的日期选择 View 。这是自定义输入 View 类的一个非常基本的示例:
ExampleBasicDateInputView.h:
#import <UIKit/UIKit.h>
@interface ExampleBasicDateInputView : UIView
@property (strong,nonatomic) UIDatePicker *datePicker;
@end
ExampleBasicDateInputView.m:
#import "ExampleBasicDateInputView.h"
@implementation ExampleBasicDateInputView{
UITextField *_inputField; // ivar to store the textfield currently being edited
}
@synthesize datePicker = _datePicker;
// TARGET METHODS
-(void)pickerValueChanged:(UIDatePicker *)picker{
_inputField.text = self.datePicker.date.description; // set text to date description
}
-(void)viewDoubleTapped:(UITapGestureRecognizer *)tapGR{
[_inputField resignFirstResponder]; // upon double-tap dismiss picker
}
-(void)textFieldBeganEditing:(NSNotification *)note{
_inputField = note.object; // set ivar to current first responder
}
-(void)textFieldEndedEditing:(NSNotification *)note{
_inputField = nil; // the first responder ended editing CRITICAL:avoids retain cycle
}
// INITI METHODS
-(void)initializationCodeMethod{
_datePicker = [[UIDatePicker alloc] initWithFrame:CGRectMake(0, 0, 320, 0)];// All pickers have preset height
self.bounds = _datePicker.frame; // Make our view same size as picker
[self addSubview:_datePicker];
[_datePicker addTarget:self action:@selector(pickerValueChanged:) forControlEvents:UIControlEventValueChanged]; // register to be notified when the value changes
// As an example we'll use a tap gesture recognizer to dismiss on a double-tap
UITapGestureRecognizer *tapGR = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(viewDoubleTapped:)];
tapGR.numberOfTapsRequired = 2; // Limit to double-taps
[self addGestureRecognizer:tapGR];
NSNotificationCenter *center = [NSNotificationCenter defaultCenter];
[center addObserver:self selector:@selector(textFieldBeganEditing:) name:UITextFieldTextDidBeginEditingNotification object:nil]; // Ask to be informed when any textfield begins editing
[center addObserver:self selector:@selector(textFieldEndedEditing:) name:UITextFieldTextDidEndEditingNotification object:nil]; // Ask to be informed when any textfield ends editing
}
-(id)init{
if ((self = [super init])){
[self initializationCodeMethod];
}
return self;
}
-(id)initWithFrame:(CGRect)frame{
if ((self = [super initWithFrame:frame])){
[self initializationCodeMethod];
}
return self;
}
-(id)initWithCoder:(NSCoder *)aDecoder{
if ((self = [super initWithCoder:aDecoder])){
[self initializationCodeMethod];
}
return self;
}
-(void)dealloc{
[[NSNotificationCenter defaultCenter] removeObserver:self name:UITextFieldTextDidBeginEditingNotification object:nil];
[[NSNotificationCenter defaultCenter] removeObserver:self name:UITextFieldTextDidEndEditingNotification object:nil];
}
@end
然后在 view did load 你会像这样使用这个类:
ExampleBasicDateInputView *dateEntryView = [[ExampleBasicDateInputView alloc] init];
self.dueDate.inputView = datePickerView;
正如您在 .h 文件中所见,我们将日期选择器实例公开为一个属性,以便您可以设置样式。像这样:
dateEntryView.datePicker.datePickerMode = UIDatePickerModeDate;
显然这是一个非常基本的例子,但我认为它展示了可以做什么。
关于iphone - XCode:当用户点击 UITextbox 时显示 UIDatePicker,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8974131/
我实际上是在尝试使用RVM在我的OSX10.7.5上更新ruby,并在输入以下命令后:rvminstallruby我得到了以下回复:Searchingforbinaryrubies,thismighttakesometime.Checkingrequirementsforosx.Installingrequirementsforosx.Updatingsystem.......Errorrunning'requirements_osx_brew_update_systemruby-2.0.0-p247',pleaseread/Users/username/.rvm/log/138121
我将应用程序升级到Rails4,一切正常。我可以登录并转到我的编辑页面。也更新了观点。使用标准View时,用户会更新。但是当我添加例如字段:name时,它不会在表单中更新。使用devise3.1.1和gem'protected_attributes'我需要在设备或数据库上运行某种更新命令吗?我也搜索过这个地方,找到了许多不同的解决方案,但没有一个会更新我的用户字段。我没有添加任何自定义字段。 最佳答案 如果您想允许额外的参数,您可以在ApplicationController中使用beforefilter,因为Rails4将参数
我意识到这可能是一个非常基本的问题,但我现在已经花了几天时间回过头来解决这个问题,但出于某种原因,Google就是没有帮助我。(我认为部分问题在于我是一个初学者,我不知道该问什么......)我也看过O'Reilly的RubyCookbook和RailsAPI,但我仍然停留在这个问题上.我找到了一些关于多态关系的信息,但它似乎不是我需要的(尽管如果我错了请告诉我)。我正在尝试调整MichaelHartl'stutorial创建一个包含用户、文章和评论的博客应用程序(不使用脚手架)。我希望评论既属于用户又属于文章。我的主要问题是:我不知道如何将当前文章的ID放入评论Controller。
我在新的Debian6VirtualBoxVM上安装RVM时遇到问题。我已经安装了所有需要的包并使用下载了安装脚本(curl-shttps://rvm.beginrescueend.com/install/rvm)>rvm,但以单个用户身份运行时bashrvm我收到以下错误消息:ERROR:Unabletocheckoutbranch.安装在这里停止,并且(据我所知)没有安装RVM的任何文件。如果我以root身份运行脚本(对于多用户安装),我会收到另一条消息:Successfullycheckedoutbranch''安装程序继续并指示成功,但未添加.rvm目录,甚至在修改我的.bas
因为我现在正在做一些时间测量,我想知道是否可以在不使用Benchmark类或命令行实用程序time的情况下测量用户时间或系统时间。使用Time类只显示挂钟时间,而不显示系统和用户时间,但是我正在寻找具有相同灵active的解决方案,例如time=TimeUtility.now#somecodeuser,system,real=TimeUtility.now-time原因是我有点不喜欢Benchmark,因为它不能只返回数字(编辑:我错了-它可以。请参阅下面的答案。)。当然,我可以解析输出,但感觉不对。*NIX系统的time实用程序也应该可以解决我的问题,但我想知道是否已经在Ruby中实
我遇到了一个非常奇怪的问题,我很难解决。在我看来,我有一个与data-remote="true"和data-method="delete"的链接。当我单击该链接时,我可以看到对我的Rails服务器的DELETE请求。返回的JS代码会更改此链接的属性,其中包括href和data-method。再次单击此链接后,我的服务器收到了对新href的请求,但使用的是旧的data-method,即使我已将其从DELETE到POST(它仍然发送一个DELETE请求)。但是,如果我刷新页面,HTML与"new"HTML相同(随返回的JS发生变化),但它实际上发送了正确的请求类型。这就是这个问题令我困惑的
我是Ruby的新手。我试过查看在线文档,但没有找到任何有效的方法。我想在以下HTTP请求botget_response()和get()中包含一个用户代理。有人可以指出我正确的方向吗?#PreliminarycheckthatProggitisupcheck=Net::HTTP.get_response(URI.parse(proggit_url))ifcheck.code!="200"puts"ErrorcontactingProggit"returnend#Attempttogetthejsonresponse=Net::HTTP.get(URI.parse(proggit_url)
有人知道如何将capybarapoltergeist的用户代理覆盖到移动用户代理以进行测试吗?我发现了一些有关为seleniumwebdriver配置它的信息:http://blog.plataformatec.com.br/2011/03/configuring-user-agents-with-capybara-selenium-webdriver/这在capybara闹鬼中怎么可能? 最佳答案 请参阅poltergeistgithub页面上的链接:https://github.com/teampoltergeist/polte
A/ctohttp://wiki.nginx.org/CoreModule#usermaster进程曾经以root用户运行,是否可以以不同的用户运行nginxmaster进程? 最佳答案 只需以非root身份运行init脚本(即/etc/init.d/nginxstart),就可以用不同的用户运行nginxmaster进程。如果这真的是你想要做的,你将需要确保日志和pid目录(通常是/var/log/nginx&/var/run/nginx.pid)对该用户是可写的,并且您所有的listen调用都是针对大于1024的端口(因为绑定(
我想验证一个电子邮件地址是否是PayPal用户。是否有API调用来执行此操作?是否有执行此操作的ruby库?谢谢 最佳答案 GetVerifiedStatus来自PayPal'sAdaptiveAccounts平台会为您做这件事。PayPal没有任何codesamples或SDKs用于Ruby中的自适应帐户,但我确实找到了编写codeforGetVerifiedStatusinRuby的人.您需要更改该代码以检查他们拥有的帐户类型的唯一更改是更改if@xml['accountStatus']!=nilaccount_status