initwithcoder

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

China☆狼群 提交于 2020-01-12 07:58:30
问题 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 class to MyCustomUIView . The problem is, when I run the code, only a blank view appears. (When I instantiate MyCustomUIView in code, it displays well.) I'm only overriding the initWithFrame: method the following way in MyCustomUIView.m : -

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

╄→尐↘猪︶ㄣ 提交于 2019-12-23 20:35:17
问题 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 setMapType:MKMapTypeSatellite]; In which worldView is a IBOutlet MKMapView object. It works under viewDidLoad , but not initWithCoder . 回答1: The objects do not yet exist when initWithCoder is called, and they do when viewDidLoad is called. Check

XCode8 initWithCoder frame Size

风格不统一 提交于 2019-12-10 16:37:48
问题 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 <autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMaxY="YES"/> and remove rect frame settings such as <rect key="frame" x="110" y="0.0" width="20" height="17"/> Removing rect frame setting is the major root cause to get width 1000 and height 1000 in the initWithCoder. Therefore, any related size

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

一曲冷凌霜 提交于 2019-12-03 14:39:49
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 class to MyCustomUIView . The problem is, when I run the code, only a blank view appears. (When I instantiate MyCustomUIView in code, it displays well.) I'm only overriding the initWithFrame: method the following way in MyCustomUIView.m : - (id)initWithFrame:(CGRect)frame { [[NSBundle mainBundle] loadNibNamed:@"MyCustomUIView" owner:self

Why isn't initWithCoder initializing items correctly?

穿精又带淫゛_ 提交于 2019-11-30 14:36:03
问题 I've got a subclass of UITableViewCell . My subclass contains several UILabel s. 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 this. My initWithCoder function is being called, and I can step through each line in my function and it appears to go through the motions. When I run my application I do not see any of the properties being applied, though. Most noticeably, the font

How to code initwithcoder in Swift?

微笑、不失礼 提交于 2019-11-30 13:33:30
问题 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 = [decoder decodeObjectForKey:@"username"]; } return self; } and in swift i'm trying like this override init() { super.init() } required init(coder decoder: NSCoder!) { self.username = (decoder.decodeObjectForKey("username")?.stringValue)! super.init(coder: decoder) }

Objective C - Custom view and implementing init method?

北城余情 提交于 2019-11-27 10:45:23
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. The right thing to do in that case is to create another method containing the code that's common to both -initWithFrame: and -initWithCoder: , and then call that method from both -initWithFrame: and -initWithCoder: : - (void)commonInit { // do any initialization that's common to both -initWithFrame: // and -initWithCoder: in this method } - (id)initWithFrame:(CGRect

Objective C - Custom view and implementing init method?

谁都会走 提交于 2019-11-26 17:58:19
问题 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. 回答1: The right thing to do in that case is to create another method containing the code that's common to both -initWithFrame: and -initWithCoder: , and then call that method from both -initWithFrame: and -initWithCoder: : - (void)commonInit { // do any