iPhone:模态视图未关闭

发布于 2024-09-11 19:03:58 字数 969 浏览 3 评论 0原文

我在 UpdateViewController 中有一个函数,由委托 MyDownloadController 调用,该函数将关闭模式视图(即 UpdateViewController)。

-(void)errorDownloading {
    self.downloadController.delegate = nil;
    [downloadController release];

    [self dismissModalViewControllerAnimated:YES];
} 

我尝试过使用或不使用委托指针来执行此操作,但它仍然不会关闭视图。

委托在 MyDownloadController 中调用如下方法:

-(void)connectionError {
    if([delegate respondsToSelector:@selector(errorDownloading)]){
        [delegate errorDownloading];
    }
}

并且该函数由不同的委托 (MyConnectionController) 调用。

这么多代表有什么问题吗?指针错误或其他问题会影响模态视图的关闭吗?如果是这样,如何/为什么?

我为代表团制定了这样的结构:

UpdateViewController (the actual modal view I am trying to close)
|- MyDownloadController (the controller that abstracts the process being done)
    |- MyConnectionController (a helper class I wrote to interact with NSURLConnection)
        |- NSURLConnection

诊断这个问题的最佳方法是什么?

I have a function, in UpdateViewController, that is being called by a delegate, MyDownloadController, that will close a modal view (which is the UpdateViewController).

-(void)errorDownloading {
    self.downloadController.delegate = nil;
    [downloadController release];

    [self dismissModalViewControllerAnimated:YES];
} 

I've tried doing this with and without messing with the delegate pointer and it still doesn't close the view.

The delegate calls the method like this within MyDownloadController:

-(void)connectionError {
    if([delegate respondsToSelector:@selector(errorDownloading)]){
        [delegate errorDownloading];
    }
}

And this function is called by a different delegate (MyConnectionController).

Is there anything wrong with having this many delegates? And would a pointer error or something with them effect the modalview being able to close? If so, how / why?

I have this structure for the delegations:

UpdateViewController (the actual modal view I am trying to close)
|- MyDownloadController (the controller that abstracts the process being done)
    |- MyConnectionController (a helper class I wrote to interact with NSURLConnection)
        |- NSURLConnection

What is the best way to diagnose this problem?

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

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

发布评论

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

评论(2

小傻瓜 2024-09-18 19:03:58

如果 downloadController 是您想要关闭的视图,我相信您发布它得太早了。

-(void)errorDownloading {
    [self dismissModalViewControllerAnimated:YES];

    self.downloadController.delegate = nil;
    [downloadController release];
} 

If downloadController is the view you want dismissed, I believe you're releasing it too soon.

-(void)errorDownloading {
    [self dismissModalViewControllerAnimated:YES];

    self.downloadController.delegate = nil;
    [downloadController release];
} 
北斗星光 2024-09-18 19:03:58

苹果文档说:

dismissModalViewControllerAnimated:

关闭接收者呈现的模态视图控制器。

意思是您在呈现要关闭的 ModalViewController 的 viewController 上调用 dismissModalViewControllerAnimated: 方法。对于您的情况,这是要使用的正确代码。

-(void)errorDownloading {
    self.downloadController.delegate = nil;
    [downloadController release];

    [self.parentViewController dismissModalViewControllerAnimated:YES];
}

另请回答您有关代表人数和指示的其他问题。更好的设计通常意味着您没有大量的委托对象字符串,但没有理由说这是错误的,恕我直言,它只会变得混乱。指针和您所描述的类似内容很可能会导致泄漏或崩溃,它不会关闭的原因是我上面指定的,您没有将该方法调用到正确的接收器。

Apple documentation says:

dismissModalViewControllerAnimated:

Dismisses the modal view controller that was presented by the receiver.

Mean's you call the the dismissModalViewControllerAnimated: method on the viewController that presented the ModalViewController you want to dismiss. in your case, this is the correct code to use.

-(void)errorDownloading {
    self.downloadController.delegate = nil;
    [downloadController release];

    [self.parentViewController dismissModalViewControllerAnimated:YES];
}

Also answer to your other questions on number of delegates and pointers. Better design usually means you don't have huge strings of delegate objects but there's little reason to say thats wrong, it just gets messy IMHO. Pointers and the such as you described would most likely cause leaks or crashes, the reason it won't close is what I specified above, you weren't calling the method to the proper receiver.

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