0

这是我的 viewcontroller1.m 按钮 userinteractionenabled 功能,

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

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

这是我的 viewcontroller2.m 按钮 userinteractionenabled 功能从 viewcontroller1.m 访问,

#import "ViewController1.h"

- (void)viewDidLoad {
   [super viewDidLoad];

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

我的viewcontroller2.h,

#import "ViewController1.h"

@interface ViewController2 : UIViewController {
StageViewController *svc;
}

@property (assign) StageViewController *svc;

但是,这是行不通的。如有错误请指正。

4

1 回答 1

1

这将是您的 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;



     }

每当您希望从另一个 ViewContoller 加载 viewController 的对象库元素时,您需要定义其 xib,然后将其相应的视图添加为当前 viewcontroller 的子视图或从当前 ViewController 推送 viewcontrller。只需使用其调用 BtnUserInteractionStatus 方法当前创建的实例无济于事..

希望能帮助到你 !!

于 2013-10-15T07:35:50.640 回答