Arrays 用外部类数组中生成的数据填充NSCOMBOX
在我的最后一个问题之后,关于从不同类访问数组,我遇到了一个新问题,这让我头痛了三天。每次我认为我有正确的解决方法时,我都失败了 嗯。。。我还没有很多关于Cocoa编程的经验。但也许你能给我一个缺少的暗示 让我向您展示我选择的方法: 1类PortConnection.h/.m中数组的声明Arrays 用外部类数组中生成的数据填充NSCOMBOX,arrays,cocoa,delegates,objective-c-2.0,nscombobox,Arrays,Cocoa,Delegates,Objective C 2.0,Nscombobox,在我的最后一个问题之后,关于从不同类访问数组,我遇到了一个新问题,这让我头痛了三天。每次我认为我有正确的解决方法时,我都失败了 嗯。。。我还没有很多关于Cocoa编程的经验。但也许你能给我一个缺少的暗示 让我向您展示我选择的方法: 1类PortConnection.h/.m中数组的声明 @interface PortConnection : NSObject { @private NSMutableArray *baudArray; } @property (nonatomic, ret
@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
我的问题是:
1我是否需要对组合框使用委托方法?
2组合框根本没有填充数据,尽管数组中填充了数据
3.我在想复杂吗
非常感谢你给我的每一个暗示
致意
塞巴斯蒂安你确定你正确钩住了组合框吗?确保将委托和数据源设置为实现了方法的任何类。好吧。。。我还没有把组合框作为代表带到课堂上。。。这也是必要的吗?我实现的方法遵循NSCOMBOX数据源协议。这是正确实现的,因为我选中了按钮:在组合框设置中的IB中使用datasource
- (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];
}