Enclosed is code to input an array to a nstableview. I originally wrote a program to first input array elements (from a text field), then display them in a third text field after their index was inputted in a second. This worked fine. However, when I added the nstableview, my array elements are not appearing in the table view. Below is my code. Would appreciate any suggestions.
#import <Cocoa/Cocoa.h>
@interface ftnstablevasm : NSObject {
IBOutlet NSTextField*input1;
IBOutlet NSTextField*input2;
IBOutlet NSTextField*output;
NSMutableArray*myArray;
NSString*myInputArray;
NSString*mySecondString;
NSNumber*myInt;
IBOutlet NSTableView*tableView;
NSString*v;
}
-(IBAction)asmbutton1NSButton*)sender;
-(IBAction)asmbutton2NSButton*)sender;
@end
#import "ftnstablevasm.h"
@implementation ftnstablevasm
-(id)init
{
[super init];
myArray=[[NSMutableArray alloc]init];
return self;
}
-(IBAction)asmbutton1NSButton*)sender;
{
myInputArray=[input1 stringValue];
[input1 setStringValue""];
[myArray addObject:myInputArray];
}
- (int)numberOfRowsInTableViewNSTableView *)aTableView
{
return [myArray count];
}
- (id)tableViewNSTableView *)aTableView
objectValueForTableColumnNSTableColumn *)aTableColumn
rowint)rowIndex
{
id theRecord, theValue;
NSParameterAssert(rowIndex >= 0 && rowIndex < [myArray count]);
theRecord = [myArray objectAtIndex:rowIndex];
theValue = [theRecord objectForKey:[aTableColumn identifier]];
return theValue;
}
-(IBAction)asmbutton2NSButton*)sender;
{
myInt=([input2 intValue]-1);
[input2 setStringValue""];
mySecondString=[myArray objectAtIndex:myInt];
[output setStringValue:mySecondString];
}
@end
#import <Cocoa/Cocoa.h>
@interface ftnstablevasm : NSObject {
IBOutlet NSTextField*input1;
IBOutlet NSTextField*input2;
IBOutlet NSTextField*output;
NSMutableArray*myArray;
NSString*myInputArray;
NSString*mySecondString;
NSNumber*myInt;
IBOutlet NSTableView*tableView;
NSString*v;
}
-(IBAction)asmbutton1NSButton*)sender;
-(IBAction)asmbutton2NSButton*)sender;
@end
#import "ftnstablevasm.h"
@implementation ftnstablevasm
-(id)init
{
[super init];
myArray=[[NSMutableArray alloc]init];
return self;
}
-(IBAction)asmbutton1NSButton*)sender;
{
myInputArray=[input1 stringValue];
[input1 setStringValue""];
[myArray addObject:myInputArray];
}
- (int)numberOfRowsInTableViewNSTableView *)aTableView
{
return [myArray count];
}
- (id)tableViewNSTableView *)aTableView
objectValueForTableColumnNSTableColumn *)aTableColumn
rowint)rowIndex
{
id theRecord, theValue;
NSParameterAssert(rowIndex >= 0 && rowIndex < [myArray count]);
theRecord = [myArray objectAtIndex:rowIndex];
theValue = [theRecord objectForKey:[aTableColumn identifier]];
return theValue;
}
-(IBAction)asmbutton2NSButton*)sender;
{
myInt=([input2 intValue]-1);
[input2 setStringValue""];
mySecondString=[myArray objectAtIndex:myInt];
[output setStringValue:mySecondString];
}
@end