您好我想分配for循環中的自定義按鈕中的特定子視圖它在目標c中正常工作,但我在swift代碼中遇到問題。swift-將值分配給子視圖中的自定義按鈕
目標的C代碼:
HButton *view = nil; // hbutton class object
NSArray *subviews = [self.superview subviews]; // storing the subviews in subviews array
NSInteger i = 0; // for index
for (view in subviews)
{
if ([view isKindOfClass:[HButton class]])
{
HButton *check=[subviews objectAtIndex:i];
if (self.tag == check.tag)
{
self.titleLabel.text [email protected]"hel";
self.backgroundColor =[UIColor orangeColor];
}
i++;
}
Swift代碼:
var view1 :BTNCustom! = nil
var subviews : NSArray = self.superview.subviews
var ival : Int = 0;
for view1 : AnyObject in subviews // I'm getting the error in this line
{
if view1.isKindOfClass(BTNCustom)
{
var check : BTNCustom = subviews.objectAtIndex(ival) as BTNCustom
if (self.tag == check.tag)
{
self.titleLabel.text = "hel";
self.backgroundColor = UIColor.orangeColor()
}
ival++;
}
}
「我收到錯誤」請註明您收到的錯誤 – newacct
您收到什麼錯誤? –