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)asmbutton1
NSButton*)sender;
-(IBAction)asmbutton2
NSButton*)sender;
@end
#import "ftnstablevasm.h"
@implementation ftnstablevasm
-(id)init
{
[super init];
myArray=[[NSMutableArray alloc]init];
return self;
}
-(IBAction)asmbutton1
NSButton*)sender;
{
myInputArray=[input1 stringValue];
[input1 setStringValue
""];
[myArray addObject:myInputArray];
}
- (int)numberOfRowsInTableView
NSTableView *)aTableView
{
return [myArray count];
}
- (id)tableView
NSTableView *)aTableView
objectValueForTableColumn
NSTableColumn *)aTableColumn
row
int)rowIndex
{
id theRecord, theValue;
NSParameterAssert(rowIndex >= 0 && rowIndex < [myArray count]);
theRecord = [myArray objectAtIndex:rowIndex];
theValue = [theRecord objectForKey:[aTableColumn identifier]];
return theValue;
}
-(IBAction)asmbutton2
NSButton*)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)asmbutton1
-(IBAction)asmbutton2
@end
#import "ftnstablevasm.h"
@implementation ftnstablevasm
-(id)init
{
[super init];
myArray=[[NSMutableArray alloc]init];
return self;
}
-(IBAction)asmbutton1
{
myInputArray=[input1 stringValue];
[input1 setStringValue
[myArray addObject:myInputArray];
}
- (int)numberOfRowsInTableView
{
return [myArray count];
}
- (id)tableView
objectValueForTableColumn
row
{
id theRecord, theValue;
NSParameterAssert(rowIndex >= 0 && rowIndex < [myArray count]);
theRecord = [myArray objectAtIndex:rowIndex];
theValue = [theRecord objectForKey:[aTableColumn identifier]];
return theValue;
}
-(IBAction)asmbutton2
{
myInt=([input2 intValue]-1);
[input2 setStringValue
mySecondString=[myArray objectAtIndex:myInt];
[output setStringValue:mySecondString];
}
@end