uidatepicker在uipopover委托 [英] uidatepicker in uipopover delegate

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

问题描述

我正在尝试使用uidatepicker插入一个uipopover,其中有两个按钮 - 取消和完成。借助 UIPopover中的UIDatePicker
< a href =http://stackoverflow.com/questions/11993096/how-can-i-show-a-uidatepicker-inside-a-popover-on-ipad-using-storyboard>如何显示一个UIDatePicker里面iPad上使用StoryBoard的Popover?

I am trying to insert a uipopover with uidatepicker in it with two buttons - Cancel and Done. I was able to design the layout using storyboard with the help of UIDatePicker in UIPopover and How can I show a UIDatePicker inside a Popover on iPad using StoryBoard?

但是,当按下完成按钮时,我无法从uidatepicker获取uiviewcontroller的日期。我是新来的ios编程,我发现代理方法非常混乱。有人可以散发光吗?
帮助非常感谢。谢谢:)

But, I am not able to get the date from uidatepicker to uiviewcontroller when Done button is pressed. I am new to ios programming and i find delegate methods very confusing. Could somebody shed some light? Help much appreciated. Thank you :)

推荐答案

你是绝对正确的一种获取视图控件中的值来实现委托函数的方法。如果您在技术层面了解,这些都非常简单。我会尝试在这里解释一下。

You are absolutely correct one way to get the value in view controller is to implement delegate functions. These are very easy if you understand at the technical level. I will try to explain it here.

您必须在datePickerViewcontrollerClass.h中定义协议,如此

you have to define the protocol in the datePickerViewcontrollerClass.h like this


@protocol TimePopupViewControllerDelegate <NSObject> 
-(void)returnSelectedDate:(NSDate*)date;
@end


并创建一个id '类型用于传递mainViewController的引用。

and create a instance of 'id' type for passing the reference of mainViewController like this.


@property(nonatomic,assign)id < TimePopupViewControllerDelegate> delegate;

@property (nonatomic, assign) id < TimePopupViewControllerDelegate > delegate;

在MainViewController.m中,您正在创建datePickerViewcontrollerClass的实例,您必须设置这样的代理

in MainViewController.m where you are creating instance of datePickerViewcontrollerClass, you have to set the delegate like this


datePickerViewcontrollerClass *myViewControllerForPopover =[[datePickerViewcontrollerClass alloc] init];
myViewControllerForPopover.delegate = self;


m类,你必须使用委托将它传递给主类。

in the method where you getting the date from picker in datePickerViewcontrollerClass.m class you have to pass it to main class using delegate.


-(void)viewDidDisappear:(BOOL)animated{
     [_delegate returnSelectedDate:datepicker.date];
[super viewWillDisappear:animated];

}



你可以用我在ViewWillDisappear或任何其他方法中写的任何方法来写这个。

you can write this in any method I have written in ViewWillDisappear or any other method.

在MainViewController之后,此方法被调用,您可以检索所选日期

After this in MainViewController this method get called and you can retrieve the selected date


-(void)returnSelectedDate:(NSDate *)date{
}


从技术上讲,您正在将mainViewController实例的引用传递给datePickerViewcontrollerClass,并从datePickerViewcontrollerClass
调用mainViewController上的方法,希望能够清楚地解释你还有疑问可以评论。

Technically you are passing the referece of mainViewController instance to your datePickerViewcontrollerClass and calling the methods on mainViewController from datePickerViewcontrollerClass I hope I will be able to explain it clearly if you still any doubt you can comment.

这篇关于uidatepicker在uipopover委托的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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