Welcome to the MacNN Forums.

If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

You are here: MacNN Forums > Software - Troubleshooting and Discussion > Developer Center > Trouble duplicating NSView

Trouble duplicating NSView
Thread Tools
Mac Enthusiast
Join Date: Mar 2003
Location: Atlanta, GA
Status: Offline
Reply With Quote
Mar 7, 2004, 01:39 PM
 
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:

Code:
- (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.
     
Mac Enthusiast
Join Date: Mar 2003
Location: Atlanta, GA
Status: Offline
Reply With Quote
Mar 8, 2004, 05:13 PM
 
Don't worry about it. I decided to just create the stuff programmatically, and it's working fine now. (btw, the reason it wasn't working before is because NSArchiver disregards the action set for the source it is archiving.)
     
   
Thread Tools
Forum Links
Forum Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On
Top
Privacy Policy
All times are GMT -5. The time now is 09:01 PM.
All contents of these forums © 1995-2011 MacNN. All rights reserved.
Branding + Design: www.gesamtbild.com
vBulletin v.3.8.7 © 2000-2011, Jelsoft Enterprises Ltd., Content Relevant URLs by vBSEO 3.3.2