Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7823533
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T08:16:57+00:00 2026-06-02T08:16:57+00:00

For learning purposes i would like to convert a cell-based NSOutlineView to a view-based

  • 0

For learning purposes i would like to convert a cell-based NSOutlineView to a view-based one,

basically i would like the following:

  • instead of a normal cell, i’d like an ‘image and text table cell view’
  • the image can be the stock NSApplicationIcon and the text can just be ‘hello world’ 🙂
  • I’d like to do this without using bindings and NSTreeController

Here is the ‘worlds simplest NSOutlineView’ example http://www.cocoasteam.com/Cocoa_Steam/Worlds_Simplest_Demo.html

I wonder if someone could modify it to make it view-based and work like i said above 🙂 🙂

I’ve tried looking at apple examples, and searching elsewhere on the internet but i still can’t get it to work – so thanks very much in advance 🙂

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-02T08:17:01+00:00Added an answer on June 2, 2026 at 8:17 am

    OK, so you want an NSOutlineView with ImageAndTextCell cells, right?

    Let’s do one of the most typical examples of this kind : a simple file explorer.

    What we’ll need :

    • an NSOutlineView (put an outline to your AppDelegate, as fileOutlineView)
    • create 3 columns in the Outline with the following Identifiers (set them up in Interface Builder) : NameColumn, SizeColumn, ModifiedColumn

    Now, as for the rest, I’ll do it all programmatically, so that you get a good idea of what’s going on…

    How to set it up (e.g. in - (void)awakeFromNib):

    // set the Data Source and Delegate
    [fileOutlineView setDataSource:(id<NSOutlineViewDataSource>)self];
    [fileOutlineView setDelegate:(id<NSOutlineViewDelegate>)self];
    
    // set the first column's cells as `ImageAndTextCell`s
    ImageAndTextCell* iatc = [[ImageAndTextCell alloc] init];
    [iatc setEditable:NO];
    [[[fileOutlineView tableColumns] objectAtIndex:0] setDataCell:iatc];
    

    Connecting the dots :

    /*******************************************************
     *
     * OUTLINE-VIEW DATASOURCE
     *
     *******************************************************/
    
    - (BOOL)outlineView:(NSOutlineView *)outlineView isItemExpandable:(id)item
    {        
        if ([item isFolder])
            return YES;
        else
            return NO;
    }
    
    - (NSInteger)outlineView:(NSOutlineView *)outlineView numberOfChildrenOfItem:(id)item
    {    
        if (item==nil)
        {
            // Root
            return [[filePath folderContentsWithPathAndBackIgnoringHidden] count];
        }
        else
        {        
            if ([item isFolder])
            {
                return [[item folderContentsWithPathAndBackIgnoringHidden] count];
            }
            else
            {
                return 0;
            }
        }
    }
    
    - (id)outlineView:(NSOutlineView *)outlineView child:(NSInteger)index ofItem:(id)item
    {
        if (item == nil)
        { 
            // Root
            return [[filePath folderContentsWithPathAndBackIgnoringHidden] objectAtIndex:index];
        }
    
        if ([item isFolder])
        {
            return [[item folderContentsWithPathAndBackIgnoringHidden] objectAtIndex:index];
        }
    
        // File
        return nil;
    }
    
    - (id)outlineView:(NSOutlineView *)outlineView objectValueForTableColumn:(NSTableColumn *)theColumn byItem:(id)item
    {          
        if ([[theColumn identifier] isEqualToString:@"NameColumn"])
        {
            return [item lastPathComponent];
        }
        else if ([[theColumn identifier] isEqualToString:@"SizeColumn"])
        {
            if ([item isFolder]) return @"--";
            else return [NSString stringWithFormat:@"%d",[item getFileSize]];
        }
        else if ([[theColumn identifier] isEqualToString:@"ModifiedColumn"])
        {
            if ([item isFolder]) return @"";
            else return [NSString stringWithFormat:@"%@",[item getDateModified]];
        }
    
        // Never reaches here
        return nil;
    }
    
    /*******************************************************
     *
     * OUTLINE-VIEW DELEGATE
     *
     *******************************************************/
    
    - (BOOL)outlineView:(NSOutlineView *)outlineView shouldSelectItem:(id)item
    {
        return YES;
    }
    
    - (BOOL)outlineView:(NSOutlineView *)outlineView isGroupItem:(id)item
    {
        return NO;
    }
    
    - (void)outlineView:(NSOutlineView *)outlineView willDisplayCell:(id)cell forTableColumn:(NSTableColumn *)tableColumn item:(id)item {
        [cell setDrawsBackground:NO];
    
        if ([item isFileHidden]) [cell setTextColor:[NSColor grayColor]];
        else [cell setTextColor:[NSColor whiteColor]];
    
        if ([[tableColumn identifier] isEqualToString:@"NameColumn"])
        {
            if ([item isFolder])
                [cell setImage:[[NSWorkspace sharedWorkspace] iconForFileType:NSFileTypeForHFSTypeCode(kGenericFolderIcon)] size:15.0];
            else
                [cell setImage:[[NSWorkspace sharedWorkspace] iconForFile:item] size:15.0];
    
            if ([item isFileHidden])
            {
                [cell setFileHidden:YES];
            }
            else
            {
                [cell setFileHidden:NO];
            }
    
        }
    
    }
    

    Hint : ImageAndTextCell class can be found here. You’ll also notice a few other methods I’m using, which are obviously NOT supported by Cocoa (e.g. isFileHidden, isFolder or folderContentsWithPathAndBackIgnoringHidden) but it’s not that difficult to implement them yourself…)

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

for learning purposes I would like to know how to implement an image (and/or)
I would like to do some parsing and tokenizing in c++ for learning purposes.
I'm learning XSLT and, for testing purposes, would like be able to simply display
For learning purposes, I would like to code a simple 2D game inspired by
I'm developing a game for windows for learning purposes (I'm learning DirectX). I would
I would like to have a go at making some simple games for personal/learning
I like reinventing the wheel for learning purposes, so I'm working on a container
For learning purposes I am writing a socket based client/server application. I have designed
For learning purposes I am writing a socket based client/server application. I have designed
I am trying to set up library like jQuery simply for learning purposes. I

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.