Re: TabView / TabViewItem / Inserting Views Problem
Re: TabView / TabViewItem / Inserting Views Problem
- Subject: Re: TabView / TabViewItem / Inserting Views Problem
- From: Jeff LaMarche <email@hidden>
- Date: Mon, 29 Oct 2001 21:56:09 -0800
Okay, I'm pretty new to Cocoa, so I'm just taking a stab at this; I'm
sure that more experienced folk will correct me if I'm off-target.
Okay, you're creating some AppKit items that you are then passing off to
other objects for their use. When, for example, you call [tabView
addTabViewItem:tabViewItem], tabView is retaining the passed object.
However, at the end of the method, you are releasing tabViewItem, rather
than autoreleasing it. Autorelease will only release your item if the
retain count has reached zero, but I believe that release will kill it
as soon as you call it, regardless of what other objects may have issued
a retain.
Is this right? (The memory handling aspects of Objective-C have been
some of the hardest parts for me to grasp, so I may not be...)
On Monday, October 29, 2001, at 08:31 PM, Sam Goldman wrote:
OK, thanks a ton to those of you who replied to my last question about
programmatically adding views to a NSTabViewItem. I have that working
now!
I am having a problem concerning similar matters. When I try to add a
new
NSTabViewItem and put a NSScrollView into it and a NSTextView into
that, the
NSTextView is acting like it doesn't exist. I believe that, due to the
order
of my code, the NSTextView is either not created or is infinitesimally
small.
I am just going to post the relevant code. It all should make sense,
but it
seems a little (a lot) cluttered.
- (void)makeNewTab:(NSString *)myTitle atPath:(NSString *)myPath
{
id *dummy;
NSTabViewItem *tabViewItem = [[NSTabViewItem alloc]
initWithIdentifier:myTitle];
NSScrollView *theScrollView;
NSTextView *theTextView;
NSString *fileContents = [[NSString stringWithContentsOfFile:myPath]
retain];
[tabViewItem setLabel:myTitle];
[tabView addTabViewItem:tabViewItem];
theScrollView = [[NSScrollView alloc] initWithFrame:[[tabViewItem
view]
bounds]];
theTextView = [[NSTextView alloc] initWithFrame:[theScrollView
bounds]];
[theScrollView setHasVerticalScroller:YES];
[tabViewItem setView:theScrollView];
[theScrollView setDocumentView:theTextView];
[theTextView setString:fileContents];
[tabView selectLastTabViewItem:(id)dummy];
[theScrollView release];
[theTextView release];
[tabViewItem release];
[fileContents release];
}
I am open to *any* suggestions.
Thanks a ton for all your help to everyone on this list!
- Sam
_______________________________________________
cocoa-dev mailing list
email@hidden
http://www.lists.apple.com/mailman/listinfo/cocoa-dev