以下代码确实有效,但它仍然让我感到沮丧,因为在else
块中,不推荐使用的方法调用会导致警告。
if ([self.navigationController respondsToSelector:@selector(dismissViewControllerAnimated:completion:)])
{
[self.navigationController dismissViewControllerAnimated:YES completion:nil];
}
else
{
//Here,the warning goes!
//dismissModalViewControllerAnimated is deprecated
[self.navigationController dismissModalViewControllerAnimated:YES];
}
如何隐藏被解雇的警告,还是有其他方法可以解决问题?
答案 0 :(得分:4)
您可以围绕相关代码行临时禁用弃用警告:
#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wdeprecated-declarations"
[self.navigationController dismissModalViewControllerAnimated:YES];
#pragma clang diagnostic pop
答案 1 :(得分:0)
我认为没有任何理由同时保留dismissViewControllerAnimated& dismissModalViewControllerAnimated。您将收到dismissModalViewControllerAnimated的警告,因为您的项目的部署目标是6.0,并且iOS 6 SDK中不推荐使用dismissModalViewControllerAnimated。