[Objective-C] This is an xib question for creating iOS Custom View.

Asked 2 years ago, Updated 2 years ago, 62 views

CustomView.h CustomView.m Custom View.xib.

You have created a view that you want to float in xib.

On the xib screen

The first question I'd like to ask here is

Placeholders' File's Onwer or View, which class is CustomView? I'm not sure if I should put it in.

From what I've tried, I think I can do both, but I don't know the exact difference.

When you designate CustomView as a custom class in File's Onwer, I want to know the difference when CustomView is designated as a custom class in View.

The second one In the initWithCoder method, self = [super initWithCoder:aDcoder]; I wonder what self is here. When you customized the File's Owner above and when you specified a custom class in View, Does self change?

The 3rd one UIView *view = [NSBundle mainBundle] What is the first object in the array from the loadNibName method and what makes [self addsubview:view]; I'd like to know the difference between self and Niproad view.

Thank you.

ios view

2022-09-22 21:52

1 Answers

That's what I think.

I understand that the first question is a matter of style. Adding CustomView as a code is specified in view, and if File's Onwer does it, xib processes it.I think we can use it without defining it separately in the m file.

As far as I know, the second question is not much different, but file's owner and self are very different, so it's a bit old, but I think it's better to read it once. http://soooprmx.com/wp/archives/4299

The third question is, because you bring the object at the top of the interface object corresponding to loadNibName, you can say that you bring the entire skeleton of the custom view, so if you do [self addsubivew: view], you attach the custom view to the view corresponding to self. (I want to know the difference between self and Niproad views, but I can't answer because I can't understand the exact question.) I'm sorry

ps. I'm also studying, so this answer can't be an accurate answer, so if there's anything wrong, please feel free to request editing or comment.


2022-09-22 21:52

If you have any answers or tips


© 2024 OneMinuteCode. All rights reserved.