iOS JSPatch热更新之实战演练

来源:互联网 发布:sql like 多个条件 编辑:程序博客网 时间:2024/05/07 21:45


哈哈哈,希望上线的代码永无bug,这样就不用热更新了。。。

//导入需要的头文件

require('UILabel,UIImageView,NSURL,NSString,UZGPersonalSetting,UIImage,UIFont,UIScreen')

require('UIColor')


defineClass("VersionUpdateController",{

        tapBackGroundView:function(tapGeture){

            //获取私有变量

            var update_type = self.valueForKey("update_type");

            if(update_type.isEqualToString("1")){

                self.removeSelf();

            }

        }

        })


defineClass("HourCell",['connectionImg','giftImg','giftLabel','giftNumLabel'],{

    reloadCell:function (model) {

        var s= UZGPersonalSetting.getInstance();

        var string=NSString.stringWithFormat("%@%@",s.image__host(),model.image());

        var str=NSURL.URLWithString(string);

        self.productImage().sd__setImageWithURL(str);

        self.titleL().setText(model.title());

            

            var cellFloat=model.price().floatValue()/model.num2().floatValue();

            var stringStr=NSString.stringWithFormat("%@.2f",model.price__type(),cellFloat.toFixed(2));

            if (model.price__type().length()==0){

                stringStr=NSString.stringWithFormat("%@",cellFloat.toFixed(2));

            }

            self.priceL().setText(stringStr);

            

            self.numL().setText(NSString.stringWithFormat("x %@", model.num2()));

            

            //动态新增property

            self.setConnectionImg();

            self.setGiftImg();

            self.setGiftLabel();

            self.setGiftNumLabel();

            

            if (model.numyy().isEqualToString("0") ||model.numyy().length ==0) {

                self.connectionImg().removeFromSuperview();

                self.giftImg().removeFromSuperview();

                self.giftLabel().removeFromSuperview();

                self.giftNumLabel().removeFromSuperview();

            } else {

                self.setConnectionImg(UIImageView.alloc().initWithFrame({x:25,y:88,width:17,height:17}));

                self.connectionImg().setImage(UIImage.imageNamed("关联ico"));

                self.contentView().addSubview(self.connectionImg());


                self.setGiftImg(UIImageView.alloc().initWithFrame({x:45,y:96,width:15,height:15}));

                self.giftImg().setImage(UIImage.imageNamed("ico"));

                self.contentView().addSubview(self.giftImg());


                self.setGiftLabel(UILabel.alloc().initWithFrame({x:67,y:90,width:UIScreen.mainScreen().bounds().width-127,height:25}));

                self.giftLabel().setFont(UIFont.systemFontOfSize(12));

                self.giftLabel().setTextColor(UIColor.colorFromHexCode("#666666"));

                self.giftLabel().setText(model.title());

                self.contentView().addSubview(self.giftLabel());


                self.setGiftNumLabel(UILabel.alloc().initWithFrame({x: UIScreen.mainScreen().bounds().width-52,y:90,width:40,height:25}));

                self.giftNumLabel().setFont(UIFont.systemFontOfSize(12));

                self.giftNumLabel().setTextAlignment(2);

                self.giftNumLabel().setTextColor(UIColor.colorFromHexCode("#666666"));

                self.giftNumLabel().setText(NSString.stringWithFormat("x %@",model.numyy()));

                self.contentView().addSubview(self.giftNumLabel());

            }

    }

});



这里要注意的是:

1:宏变量的使用:(UIColor.colorFromHexCode("#666666")

2:导入category的注意 :require('UIColor'),只需要导入原来的类就可以了

3:动态创建property ['connectionImg','giftImg','giftLabel','giftNumLabel']

            self.setConnectionImg();

            self.setGiftImg();

            self.setGiftLabel();

            self.setGiftNumLabel();


1 0