看看這個: 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
}