• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Using NSView as a template
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Using NSView as a template


  • Subject: Using NSView as a template
  • From: Matt Ball <email@hidden>
  • Date: Sun, 7 Mar 2004 16:00:41 -0500

I have created an NSView that is to serve as a template for several
more NSViews? that will be created. The code looks like this:

- (void)addBookmarksBarItem:(NSString *)title withAddress:(NSString
*)address atLocation:(int)location
{
NSData *templateBookmarksBarItem = [NSArchiver
archivedDataWithRootObject:bookmarksBarItemTemplate];
id copiedBookmarksBarItemTemplate= [NSUnarchiver
unarchiveObjectWithData:templateBookmarksBarItem];

NSView* newBookmarksBarItem = [copiedBookmarksBarItemTemplate
initWithFrame:NSMakeRect(location,0,60,16)];
[bookmarksBar addSubview:newBookmarksBarItem];
[bookmarksBarItem setTitle:title];
[bookmarksBarItem setAlternateTitle:address];
[bookmarksBarItem setAction:@selector(loadBookmarkItem:)];
}
- (IBAction)loadBookmarkItem:(id)sender
{
[[webView mainFrame] loadRequest:[NSURLRequest requestWithURL:[NSURL
URLWithString:[sender alternateTitle]]]];
}

bookmarksBarItemTemplate is the template NSView, and bookmarksBarItem
is a button that is contained inside bookmarksBarItemTemplate. I have
an outlet to both of them set up in IB.

When I run my application, it duplicates the NSView the number of times
I tell it to, but there are a few problems. Firstly, the action I set
to each button doesn't seem to be sticking. Nothing happens when I
click any of the duplicated buttons. Secondly, the first duplicated
item I create is an EXACT copy of the template (the title, etc didnt
get changed, even though I told it to change.) I've spent quite a while
trying to fix these two errors to no avail. I'd appreciate any help.

-- Matt Ball
_______________________________________________
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.


  • Follow-Ups:
    • Re: Using NSView as a template
      • From: Matt Ball <email@hidden>
    • Re: Using NSView as a template
      • From: Allan Odgaard <email@hidden>
  • Prev by Date: Looking for tips on debugging with OCUnit
  • Next by Date: Re: Iterating NSSet (was Re: My new framwork)
  • Previous by thread: Re: Looking for tips on debugging with OCUnit
  • Next by thread: Re: Using NSView as a template
  • Index(es):
    • Date
    • Thread