我想在另一个视图控制器中设置一个变量,这样当我切换到它时它就在那里,这里是代码:
CalendarMonthViewController.m
#import "ViewControllerInsert.h"
...
- (void) calendarMonthView:(TKCalendarMonthView*)monthView didSelectDate:(NSDate*)date{
NSLog(@"Date Selected: %@",date);
ViewControllerInsert *controller = [[ViewControllerInsert alloc] initWithNibName:@"ViewControllerInsert" bundle:nil];
controller.dateSelected = date;
[self.tableView reloadData];
}
日期在这里有效,当我断点或 NSLog
ViewControllerInsert.h
#import <UIKit/UIKit.h>
@interface ViewControllerInsert : UIViewController
@property(nonatomic, strong) NSDate *dateSelected;
@end
视图控制器插入.m
- (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view.
NSDate *ds = self.dateSelected;
NSString *dss = [NSString stringWithFormat:@"%@", ds];
NSLog(@"works %@",dss);
}
打印 NULL
要么我初始化不正确,要么 obj 从堆中消失。“强”不应该发生什么,对吗?