Problems with 2 ComboBoxCells inside a TableView

Hi everyone,

my name is Stefano and I'm trying to learn Obj-C and Cocoa.

I've started three weeks ago for fun, with the goal of writing a program that generates an XML from several user inputs.

I've done almost everything by myself with a lot of trials and errors but now I'm really stuck with something I can't figure it out, from several days now.

I hope that I'll be able to explain myself enough, to help you understand my issue.

I'm using a TableView driven by MVC and binding with a Class called Rating with 3 properties: system, code and reason.

Inside the TableView are three column one for each property. The first two are ComboBoxCell, the third a normal text field.

I would like to populate the second one based on the selection done on the first one.

I've already create an array for the first to populate it at startup, and it works. The second is populated by a different array for each choice made on the first.

When the app start and I click on the add button, the new row appear with the my class init default value for the first, while the second is evaluated by the if-else statements and populate with the correct array for the choice.

The problem is when I try to change the value of the first combobox. Nothing happened. The first value changes but the second combo not.

I've tried to NSLog the rating_array to see if the changes was applied to the array and it was.

I don't know how to move forward and I would like to understand the way how it could be fixed.

I hope that someone helps me. In the meantime I'll read some other Cocoa books to improve my knowledge.


P.S. I've done another simple project using only two combo boxes without the tableview and with the same code has worked perfectly. 😕


Thanks in advance for any help


Stefano




/ 
#import "Document.h"
#import "Title.h"
#import "Type.h"
#import "Production.h"
#import "Genre.h"
#import "Ratings.h"
@implementation Document
- (id)init
{
    self = [super init];
    if (self) {
        _titles_array = [[NSMutableArray alloc] init];
        _prod_array = [[NSMutableArray alloc] init];
        _genre_array = [[NSMutableArray alloc] init];
        _rating_array = [[NSMutableArray alloc] init];
    }
    return self;
}
- (NSString *)windowNibName
{
    /
    /
    return @"Document";
}
- (void)windowControllerDidLoadNib:(NSWindowController *)aController
{
    [super windowControllerDidLoadNib:aController];
    /
    [_language selectItemAtIndex:38];
    [_type selectItemAtIndex:0];
    [_subtype selectItemAtIndex:0];
    [_country selectItemAtIndex:109];
    [_original_spoken selectItemAtIndex:38];
    NSArray *systems_array=[[NSArray alloc] initWithObjects:@"ar-movies",@"au-oflc",@"fsk",@"be-movies",@"nl-movies",@"lu-movies",@"bo-movies",@"br-movies",@"bg-movies",@"ca-chvrs",@"cl-movies",@"co-movies",@"cr-movies",@"cy-movies",@"cz-movies",@"dk-movies",@"do-movies",@"ec-movies",@"sv-movies",@"ee-movies",@"fi-movies",@"fr-cnc",@"de-fsk",@"gr-movies",@"gt-movies",@"gy-movies",@"hn-movies",@"hu-movies",@"ie-ifco",@"it-movies",@"jm-movies",@"jp-eirin",@"lv-movies",@"lt-movies",@"mt-movies",@"mx-movies",@"nz-oflc",@"ni-movies",@"no-movies",@"pa-movies",@"py-movies",@"pe-movies",@"pl-movies",@"pt-movies",@"ca-rcq",@"ro-movies",@"sk-movies",@"si-movies",@"es-movies",@"sr-movies",@"se-movies",@"ch-movies",@"bbfc",@"uy-movies",@"mpaa",@"ve-movies", nil];
    [_system_cell addItemsWithObjectValues:systems_array];
   
    return;
}
+ (BOOL)autosavesInPlace
{
    return YES;
}
- (NSData *)dataOfType:(NSString *)typeName error:(NSError **)outError
{
    /
    /
    NSException *exception = [NSException exceptionWithName:@"UnimplementedMethod" reason:[NSString stringWithFormat:@"%@ is unimplemented", NSStringFromSelector(_cmd)] userInfo:nil];
    @throw exception;
    return nil;
}
- (BOOL)readFromData:(NSData *)data ofType:(NSString *)typeName error:(NSError **)outError
{
    /
    /
    /
    NSException *exception = [NSException exceptionWithName:@"UnimplementedMethod" reason:[NSString stringWithFormat:@"%@ is unimplemented", NSStringFromSelector(_cmd)] userInfo:nil];
    @throw exception;
    return YES;
}
- (IBAction)changeSystem:(id)sender {
   
    NSArray *list_AR=[[NSArray alloc] initWithObjects:@"ATP",@"SAM 13",@"SAM 16",@"SAM 18",@"Sin Calificatión", nil];
    NSArray *list_AU=[[NSArray alloc] initWithObjects:@"Not Rated",@"G",@"PG",@"M",@"MA 15+",@"R18+", nil];
    NSArray *list_AT=[[NSArray alloc] initWithObjects:@"ab 0 Jahren",@"ab 6 Jahren",@"ab 12 Jahren",@"ab 16 Jahren",@"ab 18 Jahren",@"Nicht bewertet", nil];
    NSArray *list_BE=[[NSArray alloc] initWithObjects:@"AL/G",@"6",@"9",@"12",@"16",@"18", nil];

--------many other NSARRAYs---------

    NSArray *list_US=[[NSArray alloc] initWithObjects:@"G",@"PG",@"PG-13",@"R",@"UR",@"NR", nil];
   
    NSLog(@"%@",[_rating_array[0] valueForKey:@"system"]);
    NSLog(@"%@",[_ratings objectValueOfSelectedItem]);
   
    if ([[_system_cell objectValueOfSelectedItem] isEqualTo:@"ar-movies"]){
        [_ratings removeAllItems];
        [_ratings addItemsWithObjectValues:list_AR];
    }
    else if ([[_system_cell objectValueOfSelectedItem] isEqualTo:@"au-oflc"]){
        [_ratings removeAllItems];
        [_ratings addItemsWithObjectValues:list_AU];
    }
    else if ([[_system_cell objectValueOfSelectedItem] isEqualTo:@"fsk"]){
        [_ratings removeAllItems];
        [_ratings addItemsWithObjectValues:list_AT];
    }
    else if ([[_system_cell objectValueOfSelectedItem] isEqualTo:@"be-movies"]){
        [_ratings removeAllItems];
        [_ratings addItemsWithObjectValues:list_BE];
    }

------- many other "else ifs" --------
   
    else {
        [_ratings removeAllItems];
        [_ratings addItemsWithObjectValues:list_US];
    }
   
    [_ratings reloadData];
   
}
Problems with 2 ComboBoxCells inside a TableView
 
 
Q