关于在iOS中将数据传递给委托的问题

So I have a tableview as a root screen and an add button that presents a new screen that has a datepicker. When I present the new view, I set the root screen to delegate.

Now, I need to pass the data from the uidatepicker screen back to its delegate, but I can't remember how that was supposed to work...

I know that I should be able to call a method that exists in the root screen from the new datepicker view, but again, I can't remember the syntax.

I know I have done it before, but I its been a while since I have been using Cocoa and I am just trying to recall.

Thanks for your help!!

#0

This should be enough to refresh your memory.

MyDatePickerViewController.h:

@protocol MyDatePickerViewControllerDelegate;

@interface MyDatePickerViewController;

MyDatePickerViewController : UIViewController
{
    id<MyDatePickerViewControllerDelegate> delegate;

    NSDate* selectedDate;
}

@property (nonatomic, assign) id<MyDatePickerViewControllerDelegate> delegate;
@property (nonatomic, retain) NSDate* selectedDate;

@end

@protocol MyDatePickerViewControllerDelegate
- (void)myDatePickerViewControllerDidFinish:(MyDatePickerViewController*)myDatePickerViewController;
@end

MyDatePickerViewController.m:

@implementation MyDatePickerViewController

@synthesize delegate;
@synthesize selectedDate;


- (void)dealloc
{
    [selectedDate release];
    [super dealloc];
}

- (void)someMethodCalledWhenUserIsDonePickingDate
{
    [delegate myDatePickerViewControllerDidFinish:self];
}

MyRootViewController.h:

#import MyDatePickerViewController

@interface MyRootViewController : UIViewController <MyDatePickerViewControllerDelegate>
{
    ...
}

@end

MyRootViewController.m:

@implementation MyRootViewController

- (void)myDatePickerViewControllerDidFinish:(MyDatePickerViewController*)myDatePickerViewController
{
    NSDate* date = myDatePickerViewController.selectedDate
    // Do something with the date that was chosen
}

@end

推荐文章

Node.js:是否可以捕获“TypeError”并保持服务器正常运行?

Node.js:是否可以捕获“TypeError”并保持服务器正常运行?

推荐文章

使用iPhone模拟器在接口生成器定义的对象上尝试执行任何操作时出现Monotouch iPhone开发错误

使用iPhone模拟器在接口生成器定义的对象上尝试执行任何操作时出现Monotouch iPhone开发错误

推荐文章

以结构化XML格式输出完整的Drupal页面

以结构化XML格式输出完整的Drupal页面

推荐文章

选择案例问题

选择案例问题

推荐文章

Slf4j记录器使用

Slf4j记录器使用

推荐文章

如何在android应用程序中创建图形?

如何在android应用程序中创建图形?

推荐文章

Android中的地理编码器异常

Android中的地理编码器异常

推荐文章

创建变量函数作为类的成员

创建变量函数作为类的成员

推荐文章

从子窗口获取数据

从子窗口获取数据

推荐文章

列表视图和屏幕方向

列表视图和屏幕方向

推荐文章

使用类别在目标C类中添加冲突方法

使用类别在目标C类中添加冲突方法

推荐文章

如何在Rails表单中显示相关模型中的数据

如何在Rails表单中显示相关模型中的数据

推荐文章

不同浏览器不支持从jquery获取JSON数据

不同浏览器不支持从jquery获取JSON数据

推荐文章

点击UIButton时应用程序崩溃:iphone

点击UIButton时应用程序崩溃:iphone

推荐文章

在[]中找不到rails(>=0)(Gem::LoadError)

在[]中找不到rails(>=0)(Gem::LoadError)

推荐文章

C#4.0中的代码合同

C#4.0中的代码合同