ios - 检查是否定义了协议(protocol)方法
<p><p> <a href="http://developer.apple.com/library/IOS/#documentation/UIKit/Reference/UIScrollViewDelegate_Protocol/Reference/UIScrollViewDelegate.html" rel="noreferrer noopener nofollow"><code>UIScrollViewDelegate</code></a>有一个很棒的新方法:</p>
<pre><code>// called on finger up if the user dragged. velocity is in points/second. targetContentOffset may be changed to adjust where the scroll view comes to rest. not called when pagingEnabled is YES
- (void)scrollViewWillEndDragging:(UIScrollView *)scrollView
withVelocity:(CGPoint)velocity
targetContentOffset:(inout CGPoint *)targetContentOffset __OSX_AVAILABLE_STARTING(__MAC_NA,__IPHONE_5_0)
</code></pre>
<p>但是,这<strong>仅适用于 iOS 5</strong>。对于没有这种方法的 iOS,我想使用分页作为替代方法。所以我有两个选择:</p>
<ol>
<li>检查iOS版本,<em>我不知道怎么做</em>,或者</li>
<li>检查是否为 <a href="http://developer.apple.com/library/IOS/#documentation/UIKit/Reference/UIScrollViewDelegate_Protocol/Reference/UIScrollViewDelegate.html" rel="noreferrer noopener nofollow"><code>UIScrollViewDelegate</code></a> 定义了此方法协议(protocol),<em>我也不知道该怎么做</em>。</li>
</ol>
<p>我宁愿以某种方式检查协议(protocol)中是否定义了该方法,而不是检查 iOS 版本。请注意,进行 <code>respondsToSelector:</code> 检查是不够的,因为我的实现协议(protocol)的类将始终定义它。</p></p>
<br><hr><h1><strong>Best Answer-推荐答案</ strong></h1><br>
<p><pre><code>BOOL isAtLeastIOS5 = [[ systemVersion] floatValue] >= 5.0;
</code></pre>
<p>见 <a href="https://stackoverflow.com/questions/4271454/how-to-test-a-protocol-for-a-method/4271987#4271987" rel="noreferrer noopener nofollow">How to test a protocol for a method?</a>测试给定方法的协议(protocol)。</p></p>
<p style="font-size: 20px;">关于ios - 检查是否定义了协议(protocol)方法,我们在Stack Overflow上找到一个类似的问题:
<a href="https://stackoverflow.com/questions/8053991/" rel="noreferrer noopener nofollow" style="color: red;">
https://stackoverflow.com/questions/8053991/
</a>
</p>
页:
[1]