0

在我最后一个问题之后,关于从不同类访问数组,我遇到了一个新问题,这让我头疼了三天。每次我认为我有正确的解决方法时,我都会失败。

嗯...我还没有很多关于 Cocoa 编程的经验。但也许你能给我缺失的提示。

让我告诉你我选择了什么方法:

1) PortConnection.h/.m 类中的数组声明

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

和.m中的合成

@implementation PortConnection
@synthesize baudArray;

接下来我决定在 ViewController 中实现一个方法,该方法应该负责用我需要显示的数据填充数组。类的名称是“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

以及我的方法“fillBaudSelection”的实现。

- (IBAction)fillBaudSelection:(id)sender {

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

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

此外,我实现了组合框的委托方法。

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

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

我的问题是:

1)我是否需要对组合框使用委托方法?2)组合框根本没有填充数据,尽管数组填充了数据 3)我想复杂吗?

非常感谢我从你那里得到的每一个提示!

最好的问候塞巴斯蒂安

4

1 回答 1

0

您确定您正确连接了组合框吗?确保将委托和数据源设置为已实现方法的任何类。

于 2011-06-05T14:02:21.860 回答