Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/sharepoint/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ios 检查是否定义了协议方法_Ios_Objective C Runtime_Uiscrollviewdelegate - Fatal编程技术网

Ios 检查是否定义了协议方法

Ios 检查是否定义了协议方法,ios,objective-c-runtime,uiscrollviewdelegate,Ios,Objective C Runtime,Uiscrollviewdelegate,有一个新的很棒的方法: // 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:(UIScrollVi

有一个新的很棒的方法:

// 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)
但是,这仅在iOS 5中可用。对于没有这种方法的iOS,我想使用分页作为替代方法。所以我有两个选择:

  • 检查iOS版本,我不知道怎么做,或者
  • 检查这个方法是否是为协议定义的,我也不知道怎么做
  • 我更愿意检查方法是否在协议中定义,而不是检查iOS版本。请注意,执行
    respondsToSelector:
    检查是不够的,因为实现协议的类将始终定义它

    BOOL isAtLeastIOS5 = [[[UIDevice currentDevice] systemVersion] floatValue] >= 5.0;
    

    有关协议成员可用性的有趣问题,请参阅测试给定方法的协议。

    +1。挑剔。。。将布尔重命名为isAtLeastIOS5;)+1看起来很简单,可能就是我用的。我仍然想弄清楚如何检查协议是否定义了方法。我想知道类似于
    instanceRespondsToSelector:
    的东西是否会起作用。我自己还在想办法。。。如果没有更好的答案,我会接受这个答案。
    [[[UIDevice currentDevice]systemVersion]floatValue]>4.3
    对于iOS 4.3.3是真的,因此这应该是
    [[[UIDevice currentDevice]systemVersion]floatValue]>=5.0