0

after my last question, regarding accessing an array from a different class, I ran into an new problem, that's giving me a headache for three days now. Everytime I think I have the correct solution approach, I fail.

Well... I don't have many experience yet regarding Cocoa Programming. But maybe you are able to give me the missing hint.

Let me show you what approach I've chosen:

1) the declaration of an array in the class PortConnection.h/.m

@interface PortConnection : NSObject {
@private
    NSMutableArray *baudArray;
}
@property (nonatomic, retain) NSMutableArray *baudArray;

and the synthesize in .m

@implementation PortConnection
@synthesize baudArray;

Next I decided to implement a method in the ViewController that should be in charge of filling the array with data I need for display. The name of the class is "PortTableViewController.h"

#import "PortConnection.h"

@interface PortTableViewController : NSObject <NSTableViewDataSource, NSComboBoxDataSource> {
@private
    IBOutlet NSComboBox *baudSelection;
    PortConnection *portConnection;
}

@property (assign) IBOutlet NSTableView *portTableView;

- (IBAction)fillBaudSelection:(id)sender;

@end

and the implementation of my method "fillBaudSelection".

- (IBAction)fillBaudSelection:(id)sender {

    int baudCount = [portConnection.baudArray count];
    int i;

    for (i = 0; i <= baudCount; i++){
        [baudSelection addItemWithObjectValue:[portConnection.baudArray objectAtIndex:i]];
    }
}

Furthermore I implemented the delegate methods for the combobox.

- (id)comboBox:(NSComboBox *)aComboBox objectValueForItemAtIndex:(NSInteger)index{
    return [portConnection.baudArray objectAtIndex:index];
}

- (NSInteger)numberOfItemsInComboBox:(NSComboBox *)aComboBox{
    return [portConnection.baudArray count];
}

My questions are:

1) Do I need to use the Delegate Methods for a combo box at all? 2) the Combobox isn't filled with data at all, though the array is filled with data 3) Am I thinking to complicated??

Thanks so much for every hint I get from you!

best Regards Sebastian

konturgestaltung
  • 467
  • 6
  • 19

1 Answers1

0

Are you sure you hooked the combobox correctly? make sure the delegate and the datasource are set to whatever class has the methods implemented.

Antwan van Houdt
  • 6,989
  • 1
  • 29
  • 52
  • Well... I haven't hoocked up the combobox to the class as a delegate... Is this necessary as well? The methods Ive implemented adhere to the "NSComboboxdatasource" protocol. And that is correctly implemented as I've checked the button: "Use datasource" in IB in the combo box setup – konturgestaltung Jun 06 '11 at 09:21