Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p><strong>Option A: Implement the method in a Category</strong></p> <p>Any properties used must be declared in <code>UIViewController</code>.</p> <p><code>UITableViewController</code> is a subclass of <code>UIViewController</code>. </p> <pre><code>//UIViewController+MyAdditions.h @interface UIViewController (MyAdditions) - (void)myCommonMethod; @end //UIViewController+MyAdditions.m @implementation UIViewController (MyAddtions) - (void)myCommonMethod { // insert code here } </code></pre> <p>The new method added to <code>UIViewController</code> will be inherited by <code>Bar1</code> and <code>Bar2</code></p> <p><strong>Option B: Create a <code>MyViewControllerHelper</code> class</strong></p> <p>If you can, implement your common code as a class method, otherwise you will need to create an instance of your helper class either temporarily or as a property of <code>Bar1</code> and <code>Bar2</code></p> <pre><code>@interface MyViewControllerHelper : NSObject - (void)myCommonMethod; @end @implementation MyViewControllerHelper - (void)myCommonMethod { // common code here } @interface Bar1 : UIViewController { MyViewControllerHelper *helper; } @property MyViewControllerHelper *helper; @end @implementation Bar1 @synthesize helper; - (void)someMethod { [helper myCommonMethod]; } @end @interface Bar2 : UITableViewController { MyViewControllerHelper *helper; } @property MyViewControllerHelper; @end @implementation Bar2 @synthesize helper; - (void)someOtherMethod { [helper myCommonMethod]; } @end </code></pre>
    singulars
    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. VO
      singulars
      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