Reputation: 4629
In my app I need to present a view controller. The 6.0 method for presenting a view controller is presentViewController:animated:completion:. I want to support 4.3 also. In 4.3 the method to be called is presentModalViewController:animated:. So I use respondsToSelector: to find out whether the method is supported. But when I compile the app for 6.0 it gives warning message as
presentModalViewController:animated: is deprecated: first deprecated in iOS 6.0
Can anyone know how to get rid of this warning. I also do not have 4.3 device to test whether it works. I need to assume that the code I write should work on 4.3.
if([myViewController respondsToSelector:@selector(presentModalViewController:animated:)]){
[myViewController presentModalViewController:anotherViewController animated:YES];
}else{
[myViewController presentViewController:anotherViewController animated:YES completion:nil];
}
Upvotes: 5
Views: 161
Reputation: 4629
I had mistakenly set the deployment target to 6.0. So it was showing the mentioned warning message. No warning message after I changed the deployment target to 4.3(which I need to support). Thanks for the answers!.
Upvotes: 0
Reputation: 12671
you could make check opposite for respondsToSelector
it might help, and this is the way to go actually if you are supporting older versions:)
if ([self respondsToSelector:@selector(presentViewController:animated:completion:)]){
[self presentViewController:anotherViewController animated:YES completion:nil];
} else {
[self presentModalViewController:anotherViewController animated:YES];
}
Upvotes: 3
Reputation: 3400
You can enable / disable warning with pragma into your code, but they are not very friendly to use. And i don't remember the specific pragma for this kind of warning. But some guys here will told you.
By the way you can use a simple
[id performSelector:<#(SEL)#> withObject:<#(id)#>]
will do the trick
Upvotes: 1