所以我想在我的函数之外访问和显示一个格式化的日期。对于我使用的日期格式NSDateFormatter
,效果很好..
我的函数 ( didFinishUpdatesSuccessfully
) 执行一些操作,如果成功则显示一个UIAlertView
包含格式化日期的内容。一切正常..
- (void) didFinishUpdatesSuccessfully {
//--- Create formatted date
NSDate *currDate = [NSDate date];
NSDateFormatter *dateFormatter = [[NSDateFormatter alloc]init];
[dateFormatter setDateFormat:@"dd/MM/YYYY - hh:mm:ss a"];
NSString *dateString = [dateFormatter stringFromDate:currDate]; // dateString contains the current date as a string
[dateFormatter release];
//--- UIAlertView
NSString *title = @"The update has been performed!";
UIAlertView *alert = [[UIAlertView alloc] initWithTitle: title
message: dateString
delegate: nil
cancelButtonTitle: [FileUtils appResourceForKey:@"UPDATE_GENERAL_BUTTON_TITLE_OK"]
otherButtonTitles: nil];
[alert show];
[alert release];
//--- create new string
// NSMutableString* lastUpdated = [NSMutableString stringWithFormat:@"%@",dateString];
}
我现在想将值写入dateString
全局NSString
或NSMutableString
在代码中的其他位置访问它,例如另一个函数等。
我想创建一个NSMutableString
这样的:
NSMutableString* lastUpdated = [NSMutableString stringWithFormat:@"%@",dateString];
并访问lastUpdated
其他地方,但这个功能的外面lastUpdated
是空的......你能帮忙吗?干杯