0

This is my viewcontroller1.m buttons userinteractionenabled function,

-(void) BtnUserInteractionStatus {
   oneBtn2.userInteractionEnabled = NO; 
   oneBtn3.userInteractionEnabled = NO;
}

- (void)viewDidLoad {
   [super viewDidLoad];
   [self BtnUserInteractionStatus];
}

This is my viewcontroller2.m buttons userinteractionenabled function access from viewcontroller1.m,

#import "ViewController1.h"

- (void)viewDidLoad {
   [super viewDidLoad];

   svc = [[StageViewController alloc]init];
   [svc BtnUserInteractionStatus];
}

my viewcontroller2.h,

#import "ViewController1.h"

@interface ViewController2 : UIViewController {
StageViewController *svc;
}

@property (assign) StageViewController *svc;

But, this is not working. If there is any wrong please correct it.

shankar
  • 632
  • 4
  • 14
  • what you are getting? – manujmv Oct 15 '13 at 04:48
  • that userinteractionenabled is working in viewcontroller1. But the same button created on viewcontroller2, then i just called userinteractionenabled above format is not working ... – shankar Oct 15 '13 at 04:52
  • my requirement is, buttons will move one by one i.e.., initially button1 is userinteractionenabled is Yes and all buttons is No. If button1 performs actions then button2 is enabled and so on. – shankar Oct 15 '13 at 04:55
  • This has been asked hundreds of times have you google this at all? http://stackoverflow.com/questions/1658433/accessing-method-from-other-classes-objective-c – Popeye Oct 15 '13 at 07:37

1 Answers1

1

This will be your ViewController2.m

  #import "ViewController1.h"

- (void)viewDidLoad 
 {
    [super viewDidLoad];

    svc = [[ViewController1 alloc]initWithNibName:@"ViewController1" bundle:nil];
    [self.view addSubview:svc.view];
}

ViewController2.h

    #import "ViewController1.h"

   @interface ViewController2 : UIViewController 
   {
          ViewController1 *svc;
   }

ViewController1.m

  - (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
 {
      self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
   if (self)
    {
    // Custom initialization

     [self BtnUserInteractionStatus];    /*Provide your call to BtnUserInteractionStatus within init function*/

   }
   return self;
 }




 - (void)viewDidLoad
  {
      [super viewDidLoad];
     // Do any additional setup after loading the view from its nib.


  }


   -(void)BtnUserInteractionStatus
     {

         oneBtn2.userInteractionEnabled = NO; 
         oneBtn3.userInteractionEnabled = NO;



     }

Whenever you want the object library elements of a viewController loaded from another ViewContoller you need to define its xib and then add its corresponding view as either a subview of the present viewcontroller or push the viewcontrller from the current ViewController .Simply calling the BtnUserInteractionStatus method using its currently created instance wont help..

Hope it Helps !!

Benny Dalby
  • 182
  • 4