0

以下代码确实有效,但它仍然让我感到沮丧,因为在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];
}

我怎样才能隐藏被解雇的警告,或者有没有其他方法可以解决这个问题?

4

2 回答 2

4

您可以暂时禁用相关代码行周围的弃用警告:

#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wdeprecated-declarations"

[self.navigationController dismissModalViewControllerAnimated:YES];

#pragma clang diagnostic pop
于 2013-01-19T09:27:16.643 回答
0

我看不出有任何理由同时保留dismissViewControllerAnimated 和dismissModalViewControllerAnimated。您收到了有关 dismissModalViewControllerAnimated 的警告,因为您的项目的部署目标是 6.0,并且在 iOS 6 SDK 中不推荐使用 dismissModalViewControllerAnimated。

  1. 如果您希望您的应用支持低于 6.0 的 iOS,请将部署目标更改为低于 6.0(例如 5.0)并仅使用 dismissModalViewControllerAnimated 来关闭模式。
  2. If you want your app to support iOS 6.0+, then keep deployment target as 6.0 and use only dismissViewControllerAnimated for dismissing presented controllers.
于 2013-01-19T10:17:38.163 回答