NSTableView

  • Hello,

    I am trying to figure NSTableViews out. I have two table views inside
    of my window. The code I have is completely useless and not working.
    Can anyone explain how to populate an NSTableView using arrays? If you
    could that would be greatly appreciated.

    Jeremy
    "For a long time it puzzled me how something so expensive, so leading
    edge, could be so useless, and then it occurred to me that a computer
    is a stupid machine with the ability to do incredibly smart things,
    while computer programmers are smart people with the ability to do
    incredibly stupid things. They are, in short, a perfect match." - Bill
    Bryson
  • On Fri, Feb 29, 2008 at 12:34 AM, Jeremy <doglover3049...> wrote:

    > I am trying to figure NSTableViews out. I have two table views inside
    > of my window. The code I have is completely useless and not working.
    > Can anyone explain how to populate an NSTableView using arrays? If you
    > could that would be greatly appreciated.

    You should explain how what you are trying to do differs from what is
    covered in the various basic tutorials for using NSTableViews;
    otherwise we will not know how to address your question.

    Hamish
  • This is how I am attempting to do it...

    In awakeFromNib:

    categoriesArray = [[[NSMutableArray alloc] init] retain];
    NSString *string;
    string = [NSString init];
    string = @"Main Category";
    [categoriesArray addObject:string];
    [categories selectRow:1 byExtendingSelection:NO];
    [categories scrollRowToVisible:1];

    And my informal protocols:

    - (int)numberOfRowsInTableView:(NSTableView *)aTableView
    {
    return [categoriesArray count];
    }

    - (id)tableView:(NSTableView *)aTableView objectValueForColumn:
    (NSTableColumn *)aTableColumn row:(int)row
    {
        return [categoriesArray objectAtIndex:row];
    }

    The NSTableView is not being populated at all... No rows, and nothing
    else....

    Jeremy
    "For a long time it puzzled me how something so expensive, so leading
    edge, could be so useless, and then it occurred to me that a computer
    is a stupid machine with the ability to do incredibly smart things,
    while computer programmers are smart people with the ability to do
    incredibly stupid things. They are, in short, a perfect match." - Bill
    Bryson

    On Feb 28, 2008, at 7:39 PM, Hamish Allan wrote:

    > On Fri, Feb 29, 2008 at 12:34 AM, Jeremy <doglover3049...>
    > wrote:
    >
    >> I am trying to figure NSTableViews out. I have two table views inside
    >> of my window. The code I have is completely useless and not working.
    >> Can anyone explain how to populate an NSTableView using arrays? If
    >> you
    >> could that would be greatly appreciated.
    >
    > You should explain how what you are trying to do differs from what is
    > covered in the various basic tutorials for using NSTableViews;
    > otherwise we will not know how to address your question.
    >
    > Hamish
  • On Feb 28, 2008, at 5:41 PM, Jeremy wrote:

    > In awakeFromNib:
    >
    > categoriesArray = [[[NSMutableArray alloc] init] retain];

    Here you're over-retaining an NSArray. This won't do anything if
    you're using GC, but if you're not, then you've created a memory leak.

    > NSString *string;
    > string = [NSString init];

    Never initialize a variable without allocating it memory first.

    > string = @"Main Category";

    Here you've overwritten a variable you just (incorrectly) initialized.
    If all you want is a string, then you can do this:

    NSString *string = @"Main Category";

    [...]
    > The NSTableView is not being populated at all... No rows, and
    > nothing else....

    Did you remember to set the table view's data source?

    Nick Zitzmann
    <http://www.chronosnet.com/>
  • Thanks about the memory leaks and about the allocating memory and
    stuff. And I thought that might be my problem but I am not sure how to
    actually use that method. The documentation was very vague in my
    opinion.

    Jeremy
    "For a long time it puzzled me how something so expensive, so leading
    edge, could be so useless, and then it occurred to me that a computer
    is a stupid machine with the ability to do incredibly smart things,
    while computer programmers are smart people with the ability to do
    incredibly stupid things. They are, in short, a perfect match." - Bill
    Bryson

    On Feb 28, 2008, at 7:49 PM, Nick Zitzmann wrote:

    >
    > On Feb 28, 2008, at 5:41 PM, Jeremy wrote:
    >
    >> In awakeFromNib:
    >>
    >> categoriesArray = [[[NSMutableArray alloc] init] retain];
    >
    > Here you're over-retaining an NSArray. This won't do anything if
    > you're using GC, but if you're not, then you've created a memory leak.
    >
    >> NSString *string;
    >> string = [NSString init];
    >
    > Never initialize a variable without allocating it memory first.
    >
    >> string = @"Main Category";
    >
    > Here you've overwritten a variable you just (incorrectly)
    > initialized. If all you want is a string, then you can do this:
    >
    > NSString *string = @"Main Category";
    >
    > [...]
    >> The NSTableView is not being populated at all... No rows, and
    >> nothing else....
    >
    >
    > Did you remember to set the table view's data source?
    >
    > Nick Zitzmann
    > <http://www.chronosnet.com/>
    >
  • Hi, Jeremy,

    You appear to have a few corrections that need to be made with your
    code.  To resolve these will help you on your way.  You should make
    the following changes before you try to get things working:

    1. Remove the extraneous retain from your categoriesArray
    instantiation -- -alloc and -init produce a retained object.
    2. Change:

    > NSString *string;
    > string = [NSString init];
    > string = @"Main Category";

    to

    NSString *string = @"Main Category";

    or

    NSString *string = [NSString stringWithString:@"Main Category"];

    3. Also note that [NSString init] is improper; you need [[NSString
    alloc] init] or [NSString string] -- but no matter what, it's a waste
    if you immediately set string to @"Main Category".

    4. Is your controller class with the code that you gave all set up as
    the dataSource for the table view?  You'll need to connect that in
    Interface Builder.

    If I can be of any more service, let me know.

    Cheers,
    Andrew

    On Feb 28, 2008, at 4:41 PM, Jeremy wrote:

    > This is how I am attempting to do it...
    >
    > In awakeFromNib:
    >
    > categoriesArray = [[[NSMutableArray alloc] init] retain];
    > NSString *string;
    > string = [NSString init];
    > string = @"Main Category";
    > [categoriesArray addObject:string];
    > [categories selectRow:1 byExtendingSelection:NO];
    > [categories scrollRowToVisible:1];
    >
    > And my informal protocols:
    >
    > - (int)numberOfRowsInTableView:(NSTableView *)aTableView
    > {
    > return [categoriesArray count];
    > }
    >
    > - (id)tableView:(NSTableView *)aTableView objectValueForColumn:
    > (NSTableColumn *)aTableColumn row:(int)row
    > {
    > return [categoriesArray objectAtIndex:row];
    > }
    >
    > The NSTableView is not being populated at all... No rows, and
    > nothing else....
    >
    > Jeremy
    > "For a long time it puzzled me how something so expensive, so
    > leading edge, could be so useless, and then it occurred to me that a
    > computer is a stupid machine with the ability to do incredibly smart
    > things, while computer programmers are smart people with the ability
    > to do incredibly stupid things. They are, in short, a perfect
    > match." - Bill Bryson
    >
    >
    > On Feb 28, 2008, at 7:39 PM, Hamish Allan wrote:
    >
    >> On Fri, Feb 29, 2008 at 12:34 AM, Jeremy <doglover3049...>
    >> wrote:
    >>
    >>> I am trying to figure NSTableViews out. I have two table views
    >>> inside
    >>> of my window. The code I have is completely useless and not working.
    >>> Can anyone explain how to populate an NSTableView using arrays? If
    >>> you
    >>> could that would be greatly appreciated.
    >>
    >> You should explain how what you are trying to do differs from what is
    >> covered in the various basic tutorials for using NSTableViews;
    >> otherwise we will not know how to address your question.
    >>
    >> Hamish

  • OK. Now with connecting it in IB it stills seems to be not working. I
    have made those changes that you said and nick also stated. :) But I
    am still getting a blank NSTableView. If those changes make it so that
    my code SHOULD work, I have no Idea why it isn't working... If you
    would like a copy of my project just send me a direct e-mail and I
    will send it.

    Jeremy
    "For a long time it puzzled me how something so expensive, so leading
    edge, could be so useless, and then it occurred to me that a computer
    is a stupid machine with the ability to do incredibly smart things,
    while computer programmers are smart people with the ability to do
    incredibly stupid things. They are, in short, a perfect match." - Bill
    Bryson

    On Feb 28, 2008, at 7:52 PM, Andrew Merenbach wrote:

    > Hi, Jeremy,
    >
    > You appear to have a few corrections that need to be made with your
    > code.  To resolve these will help you on your way.  You should make
    > the following changes before you try to get things working:
    >
    > 1. Remove the extraneous retain from your categoriesArray
    > instantiation -- -alloc and -init produce a retained object.
    > 2. Change:
    >
    >> NSString *string;
    >> string = [NSString init];
    >> string = @"Main Category";
    >
    > to
    >
    > NSString *string = @"Main Category";
    >
    > or
    >
    > NSString *string = [NSString stringWithString:@"Main Category"];
    >
    > 3. Also note that [NSString init] is improper; you need [[NSString
    > alloc] init] or [NSString string] -- but no matter what, it's a
    > waste if you immediately set string to @"Main Category".
    >
    > 4. Is your controller class with the code that you gave all set up
    > as the dataSource for the table view?  You'll need to connect that
    > in Interface Builder.
    >
    > If I can be of any more service, let me know.
    >
    > Cheers,
    > Andrew
    >
    > On Feb 28, 2008, at 4:41 PM, Jeremy wrote:
    >
    >> This is how I am attempting to do it...
    >>
    >> In awakeFromNib:
    >>
    >> categoriesArray = [[[NSMutableArray alloc] init] retain];
    >> NSString *string;
    >> string = [NSString init];
    >> string = @"Main Category";
    >> [categoriesArray addObject:string];
    >> [categories selectRow:1 byExtendingSelection:NO];
    >> [categories scrollRowToVisible:1];
    >>
    >> And my informal protocols:
    >>
    >> - (int)numberOfRowsInTableView:(NSTableView *)aTableView
    >> {
    >> return [categoriesArray count];
    >> }
    >>
    >> - (id)tableView:(NSTableView *)aTableView objectValueForColumn:
    >> (NSTableColumn *)aTableColumn row:(int)row
    >> {
    >> return [categoriesArray objectAtIndex:row];
    >> }
    >>
    >> The NSTableView is not being populated at all... No rows, and
    >> nothing else....
    >>
    >> Jeremy
    >> "For a long time it puzzled me how something so expensive, so
    >> leading edge, could be so useless, and then it occurred to me that
    >> a computer is a stupid machine with the ability to do incredibly
    >> smart things, while computer programmers are smart people with the
    >> ability to do incredibly stupid things. They are, in short, a
    >> perfect match." - Bill Bryson
    >>
    >>
    >> On Feb 28, 2008, at 7:39 PM, Hamish Allan wrote:
    >>
    >>> On Fri, Feb 29, 2008 at 12:34 AM, Jeremy <doglover3049...>
    >>> wrote:
    >>>
    >>>> I am trying to figure NSTableViews out. I have two table views
    >>>> inside
    >>>> of my window. The code I have is completely useless and not
    >>>> working.
    >>>> Can anyone explain how to populate an NSTableView using arrays?
    >>>> If you
    >>>> could that would be greatly appreciated.
    >>>
    >>> You should explain how what you are trying to do differs from what
    >>> is
    >>> covered in the various basic tutorials for using NSTableViews;
    >>> otherwise we will not know how to address your question.
    >>>
    >>> Hamish

    >
  • On Thu, Feb 28, 2008 at 7:55 PM, Jeremy <doglover3049...> wrote:
    > OK. Now with connecting it in IB it stills seems to be not working. I
    > have made those changes that you said and nick also stated. :) But I
    > am still getting a blank NSTableView. If those changes make it so that
    > my code SHOULD work, I have no Idea why it isn't working... If you
    > would like a copy of my project just send me a direct e-mail and I
    > will send it.

    You need to explicitly state what you mean by "connecting it in IB".
    Bindings, data source, what do you mean?

    --Kyle Sluder
  • John,

    I guess I forgot to send an e-mail saying Andrew Merenbach helped me
    out on this one. He found a small error in my code. :)

    Jeremy
    "For a long time it puzzled me how something so expensive, so leading
    edge, could be so useless, and then it occurred to me that a computer
    is a stupid machine with the ability to do incredibly smart things,
    while computer programmers are smart people with the ability to do
    incredibly stupid things. They are, in short, a perfect match." - Bill
    Bryson

    On Feb 29, 2008, at 10:47 AM, Jonathan Dann wrote:

    > Jeremy,
    >
    > Send it this way mate. I'll have a look. You on iChat? I'll screen
    > share it with you if you run leopard. Might solve your problem
    > quicker! <jonathan.dann...>
    >
    > Jonathan Dann
    >
    > On 29 Feb 2008, at 00:55, Jeremy <doglover3049...> wrote:
    >
    >> OK. Now with connecting it in IB it stills seems to be not working.
    >> I have made those changes that you said and nick also stated. :)
    >> But I am still getting a blank NSTableView. If those changes make
    >> it so that my code SHOULD work, I have no Idea why it isn't
    >> working... If you would like a copy of my project just send me a
    >> direct e-mail and I will send it.
    >>
    >> Jeremy
    >> "For a long time it puzzled me how something so expensive, so
    >> leading edge, could be so useless, and then it occurred to me that
    >> a computer is a stupid machine with the ability to do incredibly
    >> smart things, while computer programmers are smart people with the
    >> ability to do incredibly stupid things. They are, in short, a
    >> perfect match." - Bill Bryson
    >>
    >>
    >> On Feb 28, 2008, at 7:52 PM, Andrew Merenbach wrote:
    >>
    >>> Hi, Jeremy,
    >>>
    >>> You appear to have a few corrections that need to be made with
    >>> your code.  To resolve these will help you on your way.  You
    >>> should make the following changes before you try to get things
    >>> working:
    >>>
    >>> 1. Remove the extraneous retain from your categoriesArray
    >>> instantiation -- -alloc and -init produce a retained object.
    >>> 2. Change:
    >>>
    >>>> NSString *string;
    >>>> string = [NSString init];
    >>>> string = @"Main Category";
    >>>
    >>> to
    >>>
    >>> NSString *string = @"Main Category";
    >>>
    >>> or
    >>>
    >>> NSString *string = [NSString stringWithString:@"Main Category"];
    >>>
    >>> 3. Also note that [NSString init] is improper; you need [[NSString
    >>> alloc] init] or [NSString string] -- but no matter what, it's a
    >>> waste if you immediately set string to @"Main Category".
    >>>
    >>> 4. Is your controller class with the code that you gave all set up
    >>> as the dataSource for the table view?  You'll need to connect that
    >>> in Interface Builder.
    >>>
    >>> If I can be of any more service, let me know.
    >>>
    >>> Cheers,
    >>> Andrew
    >>>
    >>> On Feb 28, 2008, at 4:41 PM, Jeremy wrote:
    >>>
    >>>> This is how I am attempting to do it...
    >>>>
    >>>> In awakeFromNib:
    >>>>
    >>>> categoriesArray = [[[NSMutableArray alloc] init] retain];
    >>>> NSString *string;
    >>>> string = [NSString init];
    >>>> string = @"Main Category";
    >>>> [categoriesArray addObject:string];
    >>>> [categories selectRow:1 byExtendingSelection:NO];
    >>>> [categories scrollRowToVisible:1];
    >>>>
    >>>> And my informal protocols:
    >>>>
    >>>> - (int)numberOfRowsInTableView:(NSTableView *)aTableView
    >>>> {
    >>>> return [categoriesArray count];
    >>>> }
    >>>>
    >>>> - (id)tableView:(NSTableView *)aTableView objectValueForColumn:
    >>>> (NSTableColumn *)aTableColumn row:(int)row
    >>>> {
    >>>> return [categoriesArray objectAtIndex:row];
    >>>> }
    >>>>
    >>>> The NSTableView is not being populated at all... No rows, and
    >>>> nothing else....
    >>>>
    >>>> Jeremy
    >>>> "For a long time it puzzled me how something so expensive, so
    >>>> leading edge, could be so useless, and then it occurred to me
    >>>> that a computer is a stupid machine with the ability to do
    >>>> incredibly smart things, while computer programmers are smart
    >>>> people with the ability to do incredibly stupid things. They are,
    >>>> in short, a perfect match." - Bill Bryson
    >>>>
    >>>>
    >>>> On Feb 28, 2008, at 7:39 PM, Hamish Allan wrote:
    >>>>
    >>>>> On Fri, Feb 29, 2008 at 12:34 AM, Jeremy
    >>>>> <doglover3049...> wrote:
    >>>>>
    >>>>>> I am trying to figure NSTableViews out. I have two table views
    >>>>>> inside
    >>>>>> of my window. The code I have is completely useless and not
    >>>>>> working.
    >>>>>> Can anyone explain how to populate an NSTableView using arrays?
    >>>>>> If you
    >>>>>> could that would be greatly appreciated.
    >>>>>
    >>>>> You should explain how what you are trying to do differs from
    >>>>> what is
    >>>>> covered in the various basic tutorials for using NSTableViews;
    >>>>> otherwise we will not know how to address your question.
    >>>>>
    >>>>> Hamish

    >>>