我試圖在視圖之間返回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