変数 annoInizio と annoFine が mostrarisultato メソッド内で使用できることを望みます。どのようにできるのか?さまざまな解決策を試しましたが、できませんでした。コード内のどこでも使用されるグローバル変数を提供していると思います。
- (id)init {
if (self == [super init]) {
NSDate *adesso = [NSDate date];
NSDateComponents *adessoComponents = [[NSCalendar currentCalendar] components:(NSEraCalendarUnit | NSYearCalendarUnit | NSMonthCalendarUnit | NSDayCalendarUnit) fromDate:adesso];
//NSDate *dopo = [NSDate date];
NSDateComponents *dopoComponents = [[NSCalendar currentCalendar] components:(NSEraCalendarUnit | NSYearCalendarUnit | NSMonthCalendarUnit | NSDayCalendarUnit) fromDate:adesso];
NSDate *oggiAMezzanotte = [[NSCalendar currentCalendar] dateFromComponents:adessoComponents];
NSDate *oggifinito = [[NSCalendar currentCalendar] dateFromComponents:dopoComponents];
//[datePicker setDateValue:oggiAMezzanotte];
//[datePicker2 setDateValue:oggiAMezzanotte];
int daysToAdd = 364;
NSDate *newDate1 = [oggifinito dateByAddingTimeInterval:60*60*24*daysToAdd];
self.dataInizio = oggiAMezzanotte;
int annoInizio = [adessoComponents year];
NSLog(@"Anno inizio %i.", annoInizio);
self.dataFine = newDate1;// Sets these to "now"
NSDateComponents *newDate1Components = [[NSCalendar currentCalendar] components:(NSEraCalendarUnit | NSYearCalendarUnit | NSMonthCalendarUnit | NSDayCalendarUnit) fromDate:newDate1];
int annoFine = [newDate1Components year];
NSLog(@"Anno fine %i.", annoFine);
}
return self;
}
- (IBAction)mostrarisultato:(id)sender;
{
if (dataFine<dataInizio) {
[NSApp beginSheet:theSheet
modalForWindow:(NSWindow *)_window
modalDelegate:self
didEndSelector:nil
contextInfo:nil];
} else {
[progressIndicator startAnimation: self];
[textView setString: @""];
int lunedi = 0;
int martedi = 0;
int mercoledi = 0;
int giovedi = 0;
int venerdi = 0;
int sabato = 0;
int domenica = 0;