在视图之间传递NSString会返回NULL

时间:2014-02-26 08:37:04

标签: ios7 nsstring

我想在视图之间返回NSString。代码如下:

数据来源:

·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 个答案:

答案 0 :(得分: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
相关问题