Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

medasmx

macrumors member
Original poster
Nov 9, 2008
89
0
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:mad:""];
[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:mad:""];
mySecondString=[myArray objectAtIndex:myInt];
[output setStringValue:mySecondString];
}
@end
 

medasmx

macrumors member
Original poster
Nov 9, 2008
89
0
reloadData

I added the reloadData in the following way, still doesn't work. Thanks.

- (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;
[aTableView reloadData];
}
 

medasmx

macrumors member
Original poster
Nov 9, 2008
89
0
The below code works. Thank you for the help.
Adam

#import "ftnstablevasm.h"


@implementation ftnstablevasm

-(id)init
{
[super init];
myArray=[[NSMutableArray alloc]init];
[tableView setDelegate:self];
return self;
}
-(IBAction)asmbutton1:(NSButton*)sender;
{
myInputArray=[input1 stringValue];
[input1 setStringValue:mad:""];
[myArray addObject:myInputArray];
[tableView reloadData];
}

-(int)numberOfRowsInTableView:(NSTableView *)tv
{
return [myArray count];
}

-(id)tableView:(NSTableView *)tv objectValueForTableColumn:(NSTableColumn *)tableColumn row:(int)row
{
return [myArray objectAtIndex:row];
}

-(IBAction)asmbutton2:(NSButton*)sender;
{
myInt=([input2 intValue]-1);
[input2 setStringValue:mad:""];
mySecondString=[myArray objectAtIndex:myInt];
[output setStringValue:mySecondString];
}
@end
 

kainjow

Moderator emeritus
Jun 15, 2000
7,958
7
FYI... next time put your code in between [code] ... [/code] tags so we don't get mass frowning.
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.