-2

Can Anyone Tell me why the function is Not Calling Here

Class MasterViewController.h

@interface MasterViewController : UITableViewController 
- (void) populateTableView;

Class ModelViewController.h

#import "MasterViewController.h"
@interface ModelViewController : UIViewController
@property (strong, nonatomic) MasterViewController *MasterViewController;

Class ModelViewController.m

@synthesize MasterViewController;
[MasterViewController.self populateTableView]; // Function Calling
Akshat Anil
  • 63
  • 1
  • 7
  • 4
    A property? On a class? o.O **You go back reading an Objective-C language tutorial now.** –  Nov 01 '12 at 07:29
  • 3
    haha, thanks for the morning fun )) – Stas Nov 01 '12 at 07:30
  • i assume this [link](http://stackoverflow.com/questions/3572448/objective-c-call-function-on-another-class) shall show you the way – AppleDelegate Nov 01 '12 at 07:31
  • 3
    You actually just need to rename your property to masterViewController and call a function like: [masterViewController populateTableView]; – Stas Nov 01 '12 at 07:32
  • not able to understand the first Part "rename your property to masterViewController". – Akshat Anil Nov 01 '12 at 07:46

1 Answers1

2
@property (strong, nonatomic) MasterViewController *MasterViewController;

Here you declared a instance variable (property) with the name MasterViewController, which is the same as its class name. When you sent populateTableView message to MasterViewController, actually, the compile treated it as a Class Method (+ (void)populateTableView;) instead of Instance Method (- (void)populateTableView;).

So you'd better declare this iVar to masterViewController instead (m is lower case).

@property (strong, nonatomic) MasterViewController *masterViewController;

then alloc & use it in your method:

...
[self.masterViewController populateTableView];
Kjuly
  • 34,476
  • 22
  • 104
  • 118