Note that there are some explanatory texts on larger screens.

plurals
  1. POObjective-C calling method that been inherited from another class
    text
    copied!<p>I can't get my left sider class to interact with the view controller ivars methods, i think it may be to do multiple inheritance but i ain't got a clue on how to refactor this to solve my problem…</p> <p>JACenterViewController -> inherits CustomClass.h // create object using alloc/init…</p> <p>JALeft -> inherit JACenterViewController // i would like to say [viewController myCustomClass] helloDelegate];</p> <p>View Controller class:</p> <pre><code>#import "CustomClass.h" @interface JACenterViewController : UIViewController &lt;CustomClassDelegate&gt; @property (nonatomic, retain) CustomClass *myCustomClass; -(void)pushMe; @end #import "JACenterViewController.h" @implementation JACenterViewController @synthesize myCustomClass; // delegrate method -(void)sayHello:(CustomClass *)customClass { [customClass helloDelegate]; } // class method - (void)viewDidLoad { [super viewDidLoad]; self.myCustomClass = [[CustomClass alloc] init]; [self.myCustomClass setDelegate:self]; [[self view] addSubview:[self.myCustomClass createButton]]; } -(void)pushMe { NSLog(@"push me %@", [self class]); [myCustomClass helloDelegate]; } @end </code></pre> <p>my Custom class that VC is inheriting:</p> <pre><code>#import &lt;Foundation/Foundation.h&gt; @class CustomClass; @protocol CustomClassDelegate -(void)sayHello:(CustomClass *)customClass; @end @interface CustomClass : NSObject @property (nonatomic, assign) id delegate; @property UIButton *button; -(void)helloDelegate; -(UIButton*)createButton; @end #import "CustomClass.h" @implementation CustomClass @synthesize delegate, button; -(id)init { self = [super init]; return self; } -(void)helloDelegate { NSLog(@"Hello Delegate working!!: %@", [self class]); [self.button setTitle:@"Title" forState:UIControlStateNormal]; } -(UIButton*)createButton { self.button = [UIButton buttonWithType:UIButtonTypeRoundedRect]; [self.button setFrame:CGRectMake(0, 0, 100, 100)]; return self.button; } @end </code></pre> <p>And my finally the my left side class (BTW: this class loads from a storyboard):</p> <pre><code>#import "JACenterViewController.h" @interface JALeft : UIViewController @end #import "JALeft.h" @implementation JALeft - (void)viewDidLoad { JACenterViewController *viewController = [[JACenterViewController alloc] init]; NSLog(@"Respones %d", [[viewController myCustomClass] respondsToSelector:@selector(helloDelegate)]); NSLog(@"Respones %d", [self respondsToSelector:@selector(helloDelegate)]); NSLog(@"Respones %d", [super respondsToSelector:@selector(helloDelegate)]); /* NOT WORKING: Method should call customClass methods that has been inherited from ViewController */ [[viewController myCustomClass] helloDelegate]; } @end </code></pre> <p>I would like my JALeft class to call a method helloDelegate from the view controller class as it been inherited?</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