【问题标题】:viewdidappear not called on 2nd go roundviewdidappear 在第二轮未调用
【发布时间】:2010-11-01 13:29:06
【问题描述】:

我有 view1,当摇动时将加载 view2,并且在 view2 中按下按钮加载 view3,在 view3 中按下按钮加载 view1。当从 view3 加载 view1 时,view1 中的摇动手势不再响应摇动。

- (BOOL)canBecomeFirstResponder {
    return YES; // making view the first responder for shake event    
}


- (void)viewDidAppear:(BOOL)animated {
    [self becomeFirstResponder]; //for the shake event
    [super viewDidAppear:animated];
}


- (void)motionEnded:(UIEventSubtype)motion withEvent:(UIEvent *)event {

 if (motion==UIEventSubtypeMotionShake) {
  //adding AskAsh2VC START      
  AskAsh2VC *second = [[AskAsh2VC alloc] initWithNibName:nil bundle:nil];
  //this will set the animation style to CROSSDISSOLVE!
  second.modalTransitionStyle = UIModalTransitionStyleCrossDissolve;
  [self presentModalViewController:second animated:YES];
  [second release];
  //adding AskAsh2VC END
 }
}

- (IBAction)goToAskAsh2VC: (id) sender {
 // NSLog(@"Button WORKS!!!!");     
 //adding AskAsh2VC START
 AskAsh2VC *second = [[AskAsh2VC alloc] initWithNibName:nil bundle:nil];

 //this will set the animation style to CROSSDISSOLVE!
 second.modalTransitionStyle = UIModalTransitionStyleCrossDissolve;
 [self presentModalViewController:second animated:YES];
 [second release];
}

【问题讨论】:

    标签: objective-c ipad ios4


    【解决方案1】:

    你为什么不调用视图,一旦你展示了它就出现在 vc 上

    [self presentModalViewController:second animated:YES];
    [second viewDidAppear:YES];
    

    【讨论】:

      【解决方案2】:

      从您所说的来看,您的 view1 以模态方式呈现 view2 ...这意味着 view1 从未离开过,它只是被 view2 和所有后续视图所掩盖。而且您正在推动通常不赞成的多个模态视图。听起来您更适合加载导航控制器并将每个视图推入堆栈。当您想重置回视图 1 时,您只需 popToRootViewController 并杀死除第一个视图之外的所有内容。

      你的震动没有被注册的原因是因为它们被你的隐藏视图控制器捕获。

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2012-08-26
        • 2019-04-10
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2010-12-03
        相关资源
        最近更新 更多