看看这个: https://developer.apple.com/library/mac/#documentation/Cocoa/Conceptual/CocoaFundamentals/CommunicatingWithObjects/CommunicateWithObjects.html
有几种方法可以查看控制器之间传递数据来回。
但老实说代表是真的你真的需要这听起来像在当前的情况下。 看到这一点 - >(Passing Data between View Controllers)
说了这么多,如果你使用的代表,这里是如何--- 设置在顶部DateTableViewController.h
协议,像这样:
@protocol DateTableViewControllerDelegate <NSObject>
- (void)userSelectedThisDate:(NSDate *)d;
end
放这与其他性质
@property (nonatomic, weak) id <DateTableViewControllerDelegate> delegate;
和DateTableViewController.m
与日发回
[self.delegate userSelectedThisDate:withTheDateToSendBack];
并ServiceTableViewController.h
添加
#import "DateTableViewController.h"
@interface ServiceTableViewController : UIViewController <DateTableViewControllerDelegate>
因为你在ServiceTableViewController.m
是UINavigationController
,某处添加此当你即将推向DateTableViewController
DateTableViewController *vc = [[DateTableViewController alloc] init];
self.delegate = self;
[self.navigationController pushViewController:vc animated:YES];
终于把委托方法ServiceTableViewController.m
- (void)userSelectedThisDate:(NSDate *)d {
NSLog(@"%@", d); // this should show the returned date
}