0

我有一个子视图,当双击子视图的父视图控制器上的协议方法时,它会像这样调用......

- (void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event {
  UITouch *theTouch = [touches anyObject];
  if (theTouch.tapCount == 1) {

  } else if (theTouch.tapCount == 2) {
      if ([self.delegate respondsToSelector:@selector(editEvent:)]) {
           [self.delegate editEvent:dictionary];
      }
  }
}

这是删除字典消费代码的协议方法...

- (void)editEvent:(NSDictionary){
  EventEditViewController *eventEditViewController =
     [[EventEditViewController alloc]
     initWithNibName:@"EventEditViewController" bundle:nil];
  eventEditViewController.delegate = self;  

  navigationController = [[UINavigationController alloc]
       initWithRootViewController:eventEditViewController];
  [self presentModalViewController:navigationController animated:YES];      
  [eventEditViewController release];
}

调用协议方法并运行没有任何错误,但模态视图不会出现。

我暂时将协议方法的代码复制到了 IBAction 方法中,以便父视图按钮之一将其与子视图隔离。当我点击此按钮时,模态视图工作正常。

谁能告诉我我做错了什么?为什么从父视图上的按钮而不是从子视图调用的协议方法执行时它会起作用。

这是我迄今为止尝试解决的问题...

  1. 重新启动 xCode 和模拟器
  2. 在设备上运行 (iTouch)
  3. 呈现 e​​ventEditViewController 而不是 navigationController
  4. 使用 Push 而不是 presentModal。
  5. 使用 performSelector 直接延迟对协议的调用,延迟到调用协议方法的子视图中的另一个方法,从协议方法延迟到使用 presentModal 调用的另一个方法。
  6. 使用计时器。

我当前设置了它,以便协议方法调用呈现不同视图的已知工作方法。在调用 presentModalViewController 之前,它会弹出一个 UIAlertView 每次都有效,但是当通过协议方法调用时,模态视图拒绝显示。

我难住了。也许这与我从 UIView 类而不是 UIViewController 类调用协议方法这一事实有关。也许我需要为 subView 创建一个 UIViewController?

谢谢,

约翰

4

1 回答 1

0

With some help from another forum I have resolved this problem. I was creating the subviews from drawRect in the parent UIView. I moved the creation of the subviews to the viewController and added them as subviews to the parent scrollView. Everything works like a champ now.

John

于 2010-05-22T05:15:26.140 回答