nstableview

Discussion in 'Mac Programming' started by medasmx, Dec 24, 2008.

  1. medasmx macrumors member

    Joined:
    Nov 9, 2008
    #1
    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
     
  2. kainjow Moderator emeritus

    kainjow

    Joined:
    Jun 15, 2000
    #2
    Call [tableView reloadData]; to make it update.
     
  3. medasmx thread starter macrumors member

    Joined:
    Nov 9, 2008
    #3
    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];
    }
     
  4. Guiyon macrumors 6502a

    Joined:
    Mar 19, 2008
    Location:
    North Shore, MA
    #4
    This about this; what happens immediately after you call return at any point in a function?
     
  5. medasmx thread starter macrumors member

    Joined:
    Nov 9, 2008
    #5
    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
     
  6. kainjow Moderator emeritus

    kainjow

    Joined:
    Jun 15, 2000
    #6
    FYI... next time put your code in between [code] ... [/code] tags so we don't get mass frowning.
     

Share This Page