iPhone:模态视图未关闭
我在 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
如果 downloadController 是您想要关闭的视图,我相信您发布它得太早了。
If downloadController is the view you want dismissed, I believe you're releasing it too soon.
苹果文档说:
意思是您在呈现要关闭的 ModalViewController 的 viewController 上调用 dismissModalViewControllerAnimated: 方法。对于您的情况,这是要使用的正确代码。
另请回答您有关代表人数和指示的其他问题。更好的设计通常意味着您没有大量的委托对象字符串,但没有理由说这是错误的,恕我直言,它只会变得混乱。指针和您所描述的类似内容很可能会导致泄漏或崩溃,它不会关闭的原因是我上面指定的,您没有将该方法调用到正确的接收器。
Apple documentation says:
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.
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.