2014-02-26 56 views
1

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

我的問題是什麼?

+1

看起來像' - (NSDate *)日期'永不調用,'selectedDate'沒有填充正確的值。 – sage444

回答

1
Please do this 
VIEWNAME *firstviewObj=[[VIEWName alloc]init]; 
NSDate *myDate = [firstviewobj date]; 
NSLog(@"%@",firstviewObj.selectedDate); 

Remember myDate and firstviewObj.selectDate will give same result 
+0

新帖有錯誤返回 –

+0

什麼是錯誤? – Saurav

+0

後添加..... –