JSPatch新增协议方法

2017-12-19  本文已影响13人  anny_4243

OC代码:

- (CGSize) collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout sizeForItemAtIndexPath:(NSIndexPath *)indexPath
{
    return CGSizeMake((screenWidth-35)/self.dataArray.count,85);
}

JS代码:

defineClass("NewHomeHeadView:UIView<UICollectionViewDelegateFlowLayout>", {
            collectionView_layout_sizeForItemAtIndexPath: function(collectionView, collectionViewLayout, indexPath) {
            var screenBounds = UIScreen.mainScreen().bounds();
            return {width:(screenBounds.width-35) / self.dataArray().count(), height:85};
            }
            }, {});

注:由于sizeForItemAtIndexPath方法是UICollectionViewDelegateFlowLayout协议的方法,在原来的代码中没有遵从UICollectionViewDelegateFlowLayout协议,现在想要实现其中的方法就要按照上面的形式在类名后面加上协议。

如果不加协议在测试环境运行没有问题,但是在正式环境上运行,就会发现并没有实现协议方法。

上一篇 下一篇

猜你喜欢

热点阅读