0

我有简单的评分应用程序,我有;

 @IBInspectable var commingId: Int
        {
        get
        {
            return self.commingId;
        }
        set
        {
            refreshStars()
        }
    }


func starClicked(sender:UIButton){
    if(self.canEdit){
        rating = sender.tag;
        if(self.delegate != nil){
            self.delegate.starRateEdited(Double(rating))
        }

        self.refreshStars()
        print("Selected \(sender.tag) - commingId \(self.commingId)")



    }
}

代码。当我试图得到回报时self.commingId给了我;

EXC_BAD_ACCESS(code=2,address=0x7fff571egff8) 错误

我怎样才能commingId进去?

4

2 回答 2

1

你为什么还要重新定义getter?

看起来您只需要refreshStars()在设置值后调用,所以只需使用willSet/didSet

@IBInspectable var commingId: Int {
    didSet {
        refreshStars()
    }
}
于 2016-10-13T11:21:52.783 回答
-1

尝试以下:

var commingRating: Int = 0

@IBInspectable var commingId: Int
            {
            get
            {
                return self.commingRating;
            }
            set
            {
                commingRating = newValue
                refreshStars()
            }
        }


    func starClicked(sender:UIButton){
        if(self.canEdit){
            rating = sender.tag;
            if(self.delegate != nil){
                self.delegate.starRateEdited(Double(rating))
            }

            self.refreshStars()
            print("Selected \(sender.tag) - commingId \(self.commingId)")



        }
    }
于 2016-10-13T10:50:36.107 回答