Questions tagged [initwithcoder]

49 questions
27
votes
3 answers

Objective C - Custom view and implementing init method?

I have a custom view that I want to be able to initialize both in-code and in nib. What's the correct way to write both initWithFrame and initWithCoder methods? They both share a block of code that is used for some initialization.
aryaxt
  • 76,198
  • 92
  • 293
  • 442
19
votes
1 answer

Why isn't initWithCoder initializing items correctly?

I've got a subclass of UITableViewCell. My subclass contains several UILabels. I want my subclass to initialize these labels to some default settings that applies to every table view cell of mine. I read that I should be using initWithCoder for…
Ryan
  • 7,733
  • 10
  • 61
  • 106
8
votes
4 answers

When do you use encodeWithCoder: and initWithCoder: on the iPhone?

As my question in the subject above states, what requirements do you typically have to meet in order to say "Ok, I need encodeWithCoder: and initWithCoder: instantiation for this"? Typically you can write object state to NSUserDefaults, so I'm…
Coocoo4Cocoa
  • 48,756
  • 50
  • 150
  • 175
7
votes
2 answers

Load custom UIView with XIB from a View Controller's view using IB

I have a custom UIView (MyCustomUIView) which is built using Interface Builder. I'd like to place this custom view in MyViewController's view, which is also designed using IB. I've placed an UIView as a subview in MyViewController's XIB and set it's…
Daniel
  • 73
  • 1
  • 1
  • 6
6
votes
1 answer

How to code initwithcoder in Swift?

i'm newbie in swift adn i have problem with initwithcoder in swift. I have class UserItem, i need it to save user login. in objective c is like this - (id)initWithCoder:(NSCoder *)decoder{ if (self = [super init]){ self.username =…
Dian Sigit
  • 71
  • 1
  • 1
  • 2
6
votes
1 answer

Setting Finished TabBar images when using storyboards?

I am working on an application where the bulk of the UI is setup via a Storyboard in Xcode. One thing that I want to do is specify "Finished" images for the UITabBarItems on a TabBar rather than the default "Stencilled" images that you can access…
fuzzygoat
  • 26,573
  • 48
  • 165
  • 294
5
votes
4 answers

NSCoding and saving/loading default values issue

I'm writing some code for an iPhone app, and I'm having issues getting default data to load in correctly. I am basing my code off some example from the "Learning Cocos2d" book by Ray Wenderlich. It seems that even when I delete the app outright…
Mark Tuttle
  • 185
  • 1
  • 1
  • 9
4
votes
3 answers

NSOpenGLView with OpenGL 3.2 Core

I apologies in advance if this question will be trivial or a nonsense...this is one of the first app that I'm developing. (Unfortunatley) I'm not a developer. I have a NSWindow which contains a custom View which is a subclass of NSOpenGLView. Since…
Andrea3000
  • 1,018
  • 1
  • 11
  • 26
4
votes
0 answers

XCode8 initWithCoder frame Size

Found if use XCode 8 XIB file, the UIView initWithCoder will get frame (0, 0, 1000, 1000) instead of the XIB frame size setting. Check the diff of XIB xml file it will add
Yang Young
  • 602
  • 5
  • 6
4
votes
0 answers

iOS : initWithCoder fail : 'Exercised class for selector implementation needs to be pushed'

I have an UIImageView subclassed as CLImageView that has been implemented with lazy load. Just ago I have encountered this error message : Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'Exercised class for…
CheeseLemon
  • 126
  • 8
3
votes
2 answers

ios: questions regarding init(frame:) and init?(coder:)

Apple's tutorial describes the difference between init(frame:) and init?(coder:) as You typically create a view in one of two ways: by programatically initializing the view, or by allowing the view to be loaded by the storyboard. There’s a…
user8822312
  • 255
  • 4
  • 14
3
votes
0 answers

Access custom view's user-defined runtime attributes from initWithCoder

I have instances of a custom view class in a XIB that I need to initialize by calling a custom initializer that takes certain parameters. In order to configure these in interface builder I need to pass those parameters somehow to the initializer,…
devios1
  • 36,899
  • 45
  • 162
  • 260
3
votes
0 answers

Check whether UIView is loaded from a Nib/Storyboard or was created programmatically

Is there any way to identify whether a UIView is loaded from a nib file/Storyboard, or instantiated dynamically from user code? I am creating a custom UIView subclass so I have full access to instance methods. Would checking whether initWithCoder:…
Can Poyrazoğlu
  • 33,241
  • 48
  • 191
  • 389
3
votes
2 answers

IBOutlet is nil after initWithCoder is called

Simple problem, I have defined a UIImageView, called bigImageView in a UIViewController using the storyboard, It's declared in the h file of that UIViewController as follows: @property (retain, nonatomic) IBOutlet UIImageView *bigImageView; on my…
Alon_T
  • 1,430
  • 4
  • 26
  • 47
3
votes
2 answers

Objective-C iOS Development Using viewDidLoad or initWithCoder when setting Variables and Why?

So it seems like I should be setting my member variables in viewDidLoad - but I am confused as to why setting these variables in initWithCoder fails, since both are called at the start of the program. In particular I have a line of code: [worldView…
user3084415
  • 75
  • 2
  • 8
1
2 3 4