2014-02-26 22 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

后添加..... –