Advertise Mobile SDKs Books Events Forum News Social Networking Support Us
Follow @iphonedevsdk on Twitter

Interface 2, Advanced iOS
Mockup & Code Gen
($9.99)

Make your own iPhone apps
and run them live!
(free)

Pic Frame Dynamo: Photo Editing
($0.99)

Abiliator
($1.99)

Want your application or service advertised on iPhone Dev SDK?

Go Back   iPhone Dev SDK Forum > iPhone SDK Development Forums > iPhone SDK Development

Reply
 
LinkBack Thread Tools Display Modes
Old 03-04-2011, 10:18 PM   #1 (permalink)
Registered Member
 
Join Date: Mar 2011
Posts: 1
evanskis is on a distinguished road
Default initWithCoder: getting called by both nib & NSCoding!!!

Ok, I'm having a lot of problems right now trying to get initWithCoder: to work right. I have a nib file that gets loaded, and in my app delegate, I call unarchiveWithFile: for the view controller that is associated with that nib, and now my app crashes. I can see that initWithCoder: is being called twice, presumably once from when awakeFromNib: is called, and then from when I call unarchiveWithFile: since the view controller conforms to NSCoding. But now either it crashes as soon as the view loads or when I press an IBOutlet. Any suggestions??

Here's the code for initWithCoder:

Code:
- (id)initWithCoder:(NSCoder *)coder {
    [super initWithCoder:coder];
    [[self mapView] addAnnotations:[[coder decodeObjectForKey:@"Annotations"] retain]];
    return self;
}
All I'm doing is decoding an array of annotations for a map view, but somewhere along the line this method is being called twice and then it crashes.
evanskis is offline   Reply With Quote
Old 03-05-2011, 06:14 AM   #2 (permalink)
Registered Member
 
Join Date: Jan 2011
Age: 24
Posts: 40
FlyingV is on a distinguished road
Default

why don't you save only the datas of the annotations? and in the viewdidload you add them, after your viewcontroller loaded from the nib.

Quote:
Originally Posted by evanskis View Post
Ok, I'm having a lot of problems right now trying to get initWithCoder: to work right. I have a nib file that gets loaded, and in my app delegate, I call unarchiveWithFile: for the view controller that is associated with that nib, and now my app crashes. I can see that initWithCoder: is being called twice, presumably once from when awakeFromNib: is called, and then from when I call unarchiveWithFile: since the view controller conforms to NSCoding. But now either it crashes as soon as the view loads or when I press an IBOutlet. Any suggestions??

Here's the code for initWithCoder:

Code:
- (id)initWithCoder:(NSCoder *)coder {
    [super initWithCoder:coder];
    [[self mapView] addAnnotations:[[coder decodeObjectForKey:@"Annotations"] retain]];
    return self;
}
All I'm doing is decoding an array of annotations for a map view, but somewhere along the line this method is being called twice and then it crashes.
FlyingV is offline   Reply With Quote
Reply

Bookmarks

Tags
initwithcoder, iphone, nib, nscoding

Thread Tools
Display Modes

Posting 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



» Advertisements
» Online Users: 371
17 members and 354 guests
Absentia, akphyo, apatsufas, BinHex, dre, Error404, fredidf, Gaz, gmarro, jeroenkeij, Kirkout, MarkC, mottdog, Music Man, PavelMik, whitey99, Wikiboo
Most users ever online was 1,387, 04-10-2012 at 04:21 AM.
» Stats
Members: 175,666
Threads: 94,120
Posts: 402,898
Top Poster: BrianSlick (7,990)
Welcome to our newest member, cpsclicker
Powered by vBadvanced CMPS v3.1.0

All times are GMT -5. The time now is 03:20 AM.
Powered by vBulletin® Version 3.8.0
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.3.0