Using NSView as a template
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
unarchiveObjectWith
Data: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.