当从协议方法调用时,presentModalViewController 不想工作

发布于 2024-09-02 15:40:38 字数 1606 浏览 4 评论 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. 呈现 eventEditViewController 而不是 navigationController
  4. 使用 Push 而不是presentModal。
  5. 使用performSelector延迟对协议的调用,直接延迟到协议,延迟到子视图中调用协议方法的另一个方法,使用presentModal调用从协议方法延迟到另一个方法。
  6. 使用计时器。

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

我很困惑。也许这与我从 UIView 类而不是 UIViewController 类调用协议方法有关。也许我需要为子视图创建一个 UIViewController ?

谢谢,

约翰

I have a subview that when double tapped a protocol method on the subview's parent view controller is called like this...

- (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];
      }
  }
}

Here is the protocol method with the dictionary consuming code removed...

- (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];
}

The protocol method is called and runs without any errors but the modal view does not present itself.

I temporarily copied the protocol method's code to an IBAction method for one of the parent's view button's to isolate it from the subview. When I tap this button the modal view works fine.

Can anyone tell me what I am doing wrong? Why does it work when executed from a button on the parent view, and not from a protocol method called from a subview.

Here is what I have tried so far to work around the problem...

  1. Restarted xCode and the simulator
  2. Ran on the device (iTouch)
  3. Presenting eventEditViewController instead of navigationController
  4. Using Push instead of presentModal.
  5. delaying the call to the protocol with performSelector directly to the protocol, to another method in the subview which calls the protocol method, from the protocol method to another method with the presentModal calls.
  6. Using a timer.

I have it currently setup so that the protocol method calls a known working method that presents a different view. Before calling presentModalViewController it pops a UIAlertView which works every time, but the modal view refuses to display when called via the protocol method.

I'm stumped. Perhaps it has something to do with the fact that I am calling the protocol method from a UIView class instead of a UIViewController class. Maybe I need to create a UIViewController for the subView??

Thanks,

John

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

暮年 2024-09-09 15:40:38

在另一个论坛的帮助下我已经解决了这个问题。我正在父 UIView 中从 drawRect 创建子视图。我将子视图的创建移至 viewController 并将它们作为子视图添加到父滚动视图中。现在一切都像冠军一样顺利。

约翰

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

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文