NSTableView

Discussion in 'Mac Programming' started by varsis, Dec 8, 2007.

  1. varsis macrumors regular

    Joined:
    Nov 30, 2005
    #1
    Okay here is the setup. I currently Have:
    Code:
    	- (IBAction)addImage:(NSArray *)sender {
    NSOpenPanel *open = [NSOpenPanel openPanel];
    [open setCanChooseFiles:YES];
    [open setCanChooseDirectories:YES];
    [open setAllowsMultipleSelection:YES];
    NSArray *fTypes = [NSArray arrayWithObjects:
    @"jpg",
    @"png",
    @"jpeg",
    @"gif",
    @"tif",
    @"bmp",
    @"pcx",
    @"raw",
    @"pct",
    @"rsr",
    @"pxr",
    @"sct",
    @"tga",
    @"JPG",
    @"PNG",
    @"JPEG",
    @"GIF",
    @"TIF",
    @"BMP",
    @"PCX",
    @"RAW",
    @"PCT",
    @"RSR",
    @"PXR",
    @"SCT",
    @"TGA",
    nil];
    
    	int result = [open runModalForTypes:fTypes];
    	if (result == NSOKButton){
    	NSArray *selectedFiles = [open filenames];
    	int rows = [selectedFiles count];
    	int i = 0;
    while (i != rows) {
    [thumb setDataCell: [selectedFiles objectAtIndex: i]  ];
    
    	i++;
    
    	}
    
    
    What I need to do is add the NSTableView to Display the File Names and a Small Icon if possible. Also need to be able to edit and add other traits into the file. But I just can't figure it out. Anyone even help to export to the table.
     
  2. Eraserhead macrumors G4

    Eraserhead

    Joined:
    Nov 3, 2005
    Location:
    UK
    #2
    If you want to display files in general the easiest is to use NSOpenPanel which is built in. Otherwise you need to stick the objects you wish to display in an array and look up NSTableDataSource in the Documentation to see how to get them to display.
     
  3. varsis thread starter macrumors regular

    Joined:
    Nov 30, 2005
    #3
    Code:
    - (int)numberOfRowsInTableView:(NSTableView *)tableView {
    
    return [array count];
    
    }
    
    - (id)tableView:(NSTableView *)tableView objectValueForTableColumn:(NSTableColumn *)aTableColumn row:(int)row {
    	    id theRecord, theValue; //define used variables
       if(row >= 0 && row < [array count]) {
    
       theRecord = [array objectAtIndex:row];// row of Dictionary
        theValue =  [theRecord objectForKey:[aTableColumn identifier]]; // Get Object With KEY of Column
    	}
    
        return theValue;
    
    }
    Okay there is what I have for my NSTableView but it just won't work unless I specify the Array in the actual. I can't even add onto the array. It's an NSMutableArray.

    Code:
    - (IBAction)addImage:(id)sender {
    NSOpenPanel *open = [NSOpenPanel openPanel];
    [open setCanChooseFiles:YES];
    [open setCanChooseDirectories:YES];
    [open setAllowsMultipleSelection:YES];
    NSArray *fTypes = [NSArray arrayWithObjects:
    @"jpg",
    @"png",
    @"jpeg",
    @"gif",
    @"tif",
    @"bmp",
    @"pcx",
    @"raw",
    @"pct",
    @"rsr",
    @"pxr",
    @"sct",
    @"tga",
    @"JPG",
    @"PNG",
    @"JPEG",
    @"GIF",
    @"TIF",
    @"BMP",
    @"PCX",
    @"RAW",
    @"PCT",
    @"RSR",
    @"PXR",
    @"SCT",
    @"TGA",
    nil];
    
    	int result = [open runModalForTypes:fTypes];
    	if (result == NSOKButton){
    
    	array = [NSMutableArray arrayWithObjects: [NSMutableDictionary dictionaryWithObjectsAndKeys:
    			@"File tile 2",
    			@"File",
    			@"Type number 2",
    			@"File Type",
    			nil],
    			nil];
    			[tableView reloadData];
    			
    			printf ("%s", [[array objectAtIndex:0] objectForKey: @"File"]);
    
    	
    }
    }
    
    There is the other bit of code. I need to get that to add an array in. But nothing works? Anyone tell me what's wrong?

    Interface looks like:
    @interface imageTable : NSObject
    {
    IBOutlet id tableView;
    NSMutableDictionary *fileDic;
    NSMutableArray *array;
    NSMutableArray *selectedFiles;




    }
     
  4. kainjow Moderator emeritus

    kainjow

    Joined:
    Jun 15, 2000
    #4
    Are you developing this on Leopard with GC enabled? If not, you need to retain 'array' after you assign it.
     
  5. Eraserhead macrumors G4

    Eraserhead

    Joined:
    Nov 3, 2005
    Location:
    UK

Share This Page