Re: cocoa-dev digest, NSTable Examples
Re: cocoa-dev digest, NSTable Examples
- Subject: Re: cocoa-dev digest, NSTable Examples
- From: Andrew Wilson <email@hidden>
- Date: Thu, 15 Jul 2004 14:37:31 -0400
A couple of tutorials I've used to learn about tables:
http://www.macdevcenter.com/pub/a/mac/2001/08/10/cocoa.html
http://www.oreilly.com/catalog/learncocoa/apple/ch10.html
Andrew Wilson
On Jul 15, 2004, at 1:00 AM, email@hidden wrote:
--__--__--
Message: 7
Date: Wed, 14 Jul 2004 20:41:52 -0700 (PDT)
From: Kodex <email@hidden>
Subject: NSTable Examples
To: email@hidden
I am having no luck with these NSTable's so i was
wondering if anyone had any sample code out there for
a "set at launch" one column NSTable out there, so i
can tear it apart and figure out how it works better.
Thanks =)
__________________________________
Do you Yahoo!?
New and Improved Yahoo! Mail - 100MB free storage!
http://promotions.yahoo.com/new_mail
--__--__--
Message: 8
Date: Wed, 14 Jul 2004 20:48:19 -0700
To: email@hidden
From: "Louis C. Sacha" <email@hidden>
Subject: Re: Experimenting with Views (previously Noob playing with
Windows)
Cc: email@hidden
Hello...
The main problem is that in the line
NSArray *mySubViews = [[NSArray alloc] init];
you create a new empty instance of NSArray which your mySubViews
pointer points to, and then in the line
NSEnumerator *enumerator = [mySubViews objectEnumerator];
you create an enumerator from it (and since the array is empty, the
enumerator doesn't contain any objects either).
What you are really trying to do is
NSArray *mySubViews = [tabView subviews];
NSEnumerator *enumerator = [mySubViews objectEnumerator];
which will result in an enumerator that contains the subviews of the
tabview.
There are also a variety of other minor issues that you will probably
want to address.
You leak the memory used by the array mentioned above, which you
create and then replace with the array of subviews you get from the
tabview, which is easy to fix since you don't need to create the
array.
In Cocoa, the indexes of arrays are 0 based, which means that for an
array containing 2 objects, the valid indexes are 0 and 1. The test
of your for loop should limit i to values less than the count, so you
don't need to add 1 to "index". Because you are adding 1 to the count
in your loop, you are going through the loop twice even though there
is only one subview.
If you are going to use an NSEnumerator, you would generally use a
while loop based on the existence of the object returned by the
enumerator when nextObject is called, and not a for loop.
Since your enumerator is created from an empty array, it contains
nothing and the pointer returned from the nextObject call is always
nil. Likewise, the value returned from the frame method is also nil
(since you send the message to views which is nil), which is a
problem since the return type was supposed to be a struct and not a
pointer, but it didn't do anything too nasty in this particular case.
Also, the Foundation function NSStringFromRect(NSRect aRect) is great
for logging, and saves quite a bit of typing and/or copying and
pasting. The output string has the form
"{{aRect.origin.x,aRect.origin.y},{aRect.size.width,aRect.size.height}}
"
replaced with the appropriate values.
So, putting all of this together, you would end up with something like
this:
- (void)tabView:(NSTabView *)tabView
didSelectTabViewItem:(NSTabViewItem *)tabViewItem
{
NSLog(@"TAB DELEGATE tabView:didSelectTabViewItem:")
/* this gets a pointer to an array of subviews */
NSArray *mySubViews = [tabView subviews];
/* this gets an enumerator which contains the objects in the array */
NSEnumerator *enumerator = [mySubViews objectEnumerator];
NSLog(@"There are %d subviews in this view", [mySubViews count]);
NSRect frameUnionRect = NSZeroRect; /* starting with an empty rect */
/* this while loop iterates through all the objects in the
enumerator */
NSView *subview = nil;
NSRect subviewFrame;
while((subview = [enumerator nextObject]))
{
subviewFrame = [subview frame];
NSLog(@"subviewFrame is %@", NSStringFromRect(subviewFrame));
frameUnionRect = NSUnionRect(frameUnionRect, subviewFrame);
NSLog(@"frameUnionRect is %@",
NSStringFromRect(frameUnionRect));
}
/* ... do whatever else ... */
}
Hope that helps,
Louis
--__--__--
Message: 9
To: Cocoa Development <email@hidden>
From: Chris Campbell <email@hidden>
Subject: NSTableView
Date: Wed, 14 Jul 2004 22:57:02 -0500
I want to create an NSTableView where the rows aren't selectable.
- (BOOL)tableView:(NSTableView *)aTableView
shouldSelectRow:(int)rowIndex
{
return NO;
}
But one of the columns has an NSButtonCell that I want the user to
select. Denying all row selection prevents this.
Is there another way to go about this?
thanks,
Chris Campbell
--__--__--
Message: 10
Date: Wed, 14 Jul 2004 21:29:21 -0700
From: Julian Pellico <email@hidden>
To: email@hidden
Subject: 'does not respond to' warnings
Greetings,
I'm using Project Builder on 10.2.8. At one point, when I compiled my
AppController class I started getting a lot of warnings similar to the
following:
AppController.mm:109: warning: `DeckView' does not respond to `window'
AppController.mm:175: warning: `DeckView' does not respond to
`setNeedsDisplay:'
AppController.mm:171: warning: `SolverView' does not respond to
`setNeedsDisplay:'
AppController.mm:170: warning: `SolverView' does not respond to
`clearTableaus'
My AppController class has outlets that are DeckView* and SolverView*.
Both of these classes clearly inherit from NSView in the header files.
Despite these warnings, the runtime behavior seems to be correct.
I have tried cleaning my target and rebuilding, and it does not seem
to help. Has anyone seen this before? (I would search the list
archives if I could, but it seems like akamai has been bogged down of
late ;-) )
Thanks.
--__--__--
Message: 11
Cc: "Louis C. Sacha" <email@hidden>,
email@hidden
From: Larry Fransson <email@hidden>
Subject: Re: NSTable Newbie Issues
Date: Wed, 14 Jul 2004 21:50:10 -0700
To: Kodex <email@hidden>
Here's a "Doh!" check. Did you make a connection in Interface Builder
between your controller object and your tableview? Are your data
source methods being called?
Larry Fransson
Seattle, WA
--__--__--
_______________________________________________
cocoa-dev mailing list | email@hidden
Help/Unsubscribe/Archives:
http://www.lists.apple.com/mailman/listinfo/cocoa-dev
Do not post admin requests to the list. They will be ignored.
End of cocoa-dev Digest
_______________________________________________
cocoa-dev mailing list | email@hidden
Help/Unsubscribe/Archives:
http://www.lists.apple.com/mailman/listinfo/cocoa-dev
Do not post admin requests to the list. They will be ignored.