Questions tagged [initwithcoder]

49 questions
3
votes
1 answer

initWithCoder is returning 0 values for frame property

I have sub-classed uiscrollview and used initWithCoder to prepare my uiscrollview with all the subviews. I have used below code to set it up: - (id)initWithCoder:(NSCoder *)aDecoder { if ((self = [super initWithCoder:aDecoder])) { …
niroshan
  • 181
  • 10
2
votes
1 answer

Initializing a static singleton object with NSCoder

I'm working on an iPhone app and facing some troubles with my shared singleton class. I'm using a shared singleton to store two variables int gameRuns and int totalScore 'gamRuns' just increments every time the user loads the app, and 'totalScore'…
2
votes
0 answers

How we can initialise 'let' properties dynamically in it's constructor in Swift

I have created a subclass of UILabel in Swift i want to customize some properties of label like fonts,color size etc based on which type of label it is. This label is created in storyboard file. For identifying the type of labe i have created a…
Mihir Mehta
  • 13,743
  • 3
  • 64
  • 88
2
votes
1 answer

Subclass UIView with Swift, use in Nib

I am trying to subclass UIView with Swift and give my class an init with one parameter. The required Init With Coder initializer is tripping me up. I do, in fact, want to be able to plop my view into a Nib file. My understanding is that this will…
Benny B
  • 357
  • 1
  • 3
  • 13
2
votes
0 answers

initWithCoder and encodeWithEncoder hell. Can this be simplified?

With dozens of models with dozens of properties each, all able to be saved to disk using the NSCoder protocol and NSKeyed(Un)archiver, it's a lot of work to create and maintain models for my iOS application. With a dozen of properties for one model,…
Rebel Designer
  • 235
  • 4
  • 12
2
votes
1 answer

Why does initWithCoder need self.property?

I tend to regularly use self.property in my Objective C code when accessing variables as I understand that this makes use of the getter/setter methods (either explicitly coded or automatically generated). Another coder told me recently that it's…
Darren
  • 1,417
  • 13
  • 23
2
votes
1 answer

dataSource is nil in initWithCoder

I have the following initWithCoder implementation which depends on the callback of the datasource method. But somehow the datasource is nil and the datasource methods aren't called. I'm using a storyboard and therefor have overwritten the…
Moonstar
  • 247
  • 1
  • 4
  • 13
2
votes
2 answers

How do we implement custom init methods in objective-c when we use storyboard?

I have created a few buttons and labels using storyboard in XCode 4.6.3 I want to fire some methods on the click of the buttons placed in the FirstViewController and for the methods to work I have defined some variables/NSMutableArrays…
ronilp
  • 455
  • 2
  • 9
  • 25
2
votes
1 answer

Call initWithCoder explicitly or ViewDidAppear equivalent in UIView?

In a UIView I have a nav button with an IBAction & method in the top-level view controller. In the IBAction code, I flip a boolean so that when execution returns to the UIView, there's some new setup prior to drawRect: repainting the view. If all…
Tony
  • 373
  • 5
  • 18
1
vote
0 answers

Terminating app due to uncaught exception 'NSGenericException', reason: 'This coder requires that replaced objects be returned from initWithCoder:'

My iOS application is working fine in iOS 10 and newer version. But when I was trying to run my app on iPad mini with iOS version 9.3.2 then Application is crashing. I am trying to push a view controller and I am using storyboard for all view…
ajeet sharma
  • 803
  • 10
  • 37
1
vote
1 answer

InitWithCoder never called for Cocoa NSView based class

I create a XIB. I create this class called MyCustomView and assign it to the XIB's File Owner. - (instancetype)initWithCoder:(NSCoder *)aDecoder{ self = [super initWithCoder:aDecoder]; if (self) [self load]; return self; } -…
Duck
  • 34,902
  • 47
  • 248
  • 470
1
vote
1 answer

View 1000x1000 on initWithCoder:

There are a couple of questions asking this on SO but none have asked that properly. I am using a custom progress bar that is a UIView based class with this implementation. @implementation MCProgressBarView { UIImageView * _backgroundImageView; …
Duck
  • 34,902
  • 47
  • 248
  • 470
1
vote
1 answer

initWithCoder: Custom View - Determine view controller that is being instantiated

I have prepared a custom UIView subclass with an associated Xib file. On the storyboard, I place a UIView and set it's class to my custom subclass. In the custom view's initWithCoder: method, I load the xib and initialize the subviews. This works…
rhmac25
  • 256
  • 3
  • 12
1
vote
0 answers

Why does initWithCoder: return the wrong object class during object decoding?

I'm attempting to use NSKeyedArchiver / NSKeyedUnarchiver in a trivial test case and observing that when initWithCoder: is called, the object that is created reports that it has the wrong class. TestCoder.h #import…
AlleyGator
  • 1,266
  • 9
  • 13
1
vote
1 answer

Xcode NsCoding navigation title disappears

I have added this code to the "MasterViewController.m" in my project: - (void)encodeWithCoder:(NSCoder *)encoder { [encoder encodeObject:_savedText forKey:@"savedText"]; } . - (id)initWithCoder:(NSCoder *)decoder { if((self = [super init])) { …