Note that there are some explanatory texts on larger screens.

plurals
  1. POView placeholders replacement with xib using the awakeAfterUsingCoder method
    primarykey
    data
    text
    <p>I am currently working on an iOS app that has multiple xibs containing a UIView subclass which is acting as a placeholder for the header of the screen. When the view controllers are loaded from their nib, they instantiate the HeaderView placeholder. In the HeaderView class I have a method that replace the placeholder view by the real one, here is the code : </p> <pre><code>- (id)awakeAfterUsingCoder:(NSCoder *)aDecoder { if (![[self subviews] count]) { if (headerViewNib == nil) headerViewNib = [UINib frameworkNibWithNibName: @"HeaderView"]; HeaderView * headerView = [[headerViewNib instantiateWithOwner: controller options: nil] lastObject]; [headerView setTranslatesAutoresizingMaskIntoConstraints: NO]; return headerView; } return self; } </code></pre> <p>Until now, everything works correctly. But now I need to add a menu similar to a popover to the header. So I added a UIButton to the HeaderView xib, as expected it is showing in all the view controllers, but now I need to manage the touch on that button. I added a "- (IBAction)showHeaderMenu" method to my base UIViewController class, and I configured in the HeaderView.xib the file's owner to this class, so I could connect the button touch action, to the showHeaderMenu action. The problem is that I am passing "controller" as owner to the instantiateWithOwner:options: method. But this controller is nil. So my touch events on the menu button are not handled.</p> <p>So now I am searching a way to get the "controller" property set correctly. At the moment in all my view controllers xib, I connected the placeholder headerview "controller" outlet to the file's owner (which is the controller), but it does not seems to be working.</p> <p>If you have a different pattern to suggest, that does not force me to drop my HeaderView.xib or the placeholders view, i'm open :)</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

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