Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>In order to get the contents of a xib file you've got to load it first sending <code>loadNibNamed:owner:options:</code> message to NSBundle class.</p> <p>Consider you have a UIView subclass named CustomView and CustomView.xib file. In the xib file each view has a tag. Your .h file would look like:</p> <pre><code>@interface CustomView : UIView @property (nonatomic, assign) UILabel *someTextLabel; //use assign in order to not to override dealloc method @end .m @implementation CustomView - (id)init { self = [super init]; if (self) { NSArray *topLevelObjects = [[NSBundle mainBundle] loadNibNamed:@"CustomView" owner:nil options:nil]; [self addSubview:[topLevelObjects objectAtIndex:0]]; //this object is a CustomView.xib view self.someTextLabel = (UILabel *)[self viewWithTag:5]; //consider you have a UILabel on CustomView.xib that has its tag set to 5 } return self; } @end </code></pre> <p>This is about how to use .xibs for your custom UIView subclasses. If your app is like a chat then you'll have to add them programmatically.</p> <p>As for the best way to send messages between two custom views, you'll have to create a weak reference to each other in each of them.</p> <p>in one</p> <pre><code>@property (nonatomic, assign) CustomView *customView; </code></pre> <p>in another</p> <pre><code>@property (nonatomic, assign) AnotherCustomView *anotherCustomView; </code></pre> <p>and just send them messages when some even happens</p> <pre><code>- (void)buttonPressed { [customView handleButtonPressedEvent]; } </code></pre> <p>Let me know if this is clear.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload