我试图在视图之间返回NSString
。下面的代码:在视图之间传递NSString返回NULL
数据来源:
.H:
@property (nonatomic, strong) NSString *selectedDate;
.M:
@synthesise selectedDate;
-(NSDate *)date
{
NSInteger monthCount = [self.months count];
NSString *month = [self.months objectAtIndex:([self selectedRowInComponent:MONTH] % monthCount)];
NSInteger yearCount = [self.years count];
NSString *year = [self.years objectAtIndex:([self selectedRowInComponent:YEAR] % yearCount)];
NSDateFormatter *formatter = [[NSDateFormatter alloc] init]; [formatter setDateFormat:@"MMMM:yyyy"];
NSDate *date = [formatter dateFromString:[NSString stringWithFormat:@"%@:%@", month, year]];
selectedDate = [NSString stringWithFormat:@"%@", date];
return date;
}
加载视图: .M:
[VIEWNAME] *firstviewObj=[[[VIEWNAME] alloc]init];
NSLog(@"%@",firstviewObj.selectedDate);
我的问题是什么?
看起来像' - (NSDate *)日期'永不调用,'selectedDate'没有填充正确的值。 – sage444