0

appLaunched が呼び出されると、配列は null を返しますが、他の関数によって呼び出されると、配列の内容を返します。何が起こっているか知っている人はいますか?

- (id)init
 {
[super init];
theArray = [[NSMutableArray alloc] init];
theArray = [[NSUserDefaults standardUserDefaults] objectForKey:@"TheArray"];
if(!theArray) {
    theArray = [[NSMutableArray alloc] init];
} else {
    theArray = [[NSMutableArray alloc] initWithArray:theArray];
};

// NSLog(@"%@", theArray);
[[NSUserDefaults standardUserDefaults] setObject:theArray forKey:@"TheArray"];
// NSLog(@"Is saving");

return self;
}


 -(IBAction)addNewProcess:(id)sender
 {
     NSString *newProcess = [theField stringValue];
     [theArray addObject:newProcess];
     [theField setStringValue:@""];
     NSLog(@"%@", theArray);
     [theTable reloadData];

 }

 -(IBAction)removeProcess:(id)sender
 {
     int listRow = [theTable selectedRow];
     NSLog(@"%d", listRow);
     if (listRow < 0) return;
     [theArray removeObjectAtIndex:listRow];
     [theTable reloadData];
 }

 -(IBAction)save:(id)sender
 {
     NSLog(@"%@", theArray);
     int count = [theArray count];
     NSLog(@"%i", count);
     [[NSUserDefaults standardUserDefaults] setObject:theArray forKey:@"TheArray"];
     NSLog(@"Is saving");
  }

 - (NSInteger)numberOfRowsInTableView:(NSTableView *)tableView
 {
     return [theArray count];
 }

 - (id)tableView:(NSTableView *)tableView 
 objectValueForTableColumn:(NSTableColumn *)tableColumn 
             row:(NSInteger)row
 {
     return [theArray objectAtIndex:row];
 }

 - (void)tableView:(NSTableView *)tableView 
    setObjectValue:(id)object 
    forTableColumn:(NSTableColumn *)tableColumn 
               row:(NSInteger)row
 {
     [theArray replaceObjectAtIndex:row
                               withObject:object];
 }

 -(void)appLaunched:(NSNotification *)note
 {
     NSLog(@"%@", theArray);

 }


 @end
4

1 に答える 1