我有两个类,其中一个我创建了一个按钮,我想在这个类中调用一个方法。
class blueFooterForImages: UIView{
//buttons for footer
let slideButton = UIButton()
let buttonOnFooter = UIButton()
override init(frame: CGRect) {
super.init(frame: frame)
//setting buttons
slideButton.frame = CGRectMake((self.frame.width / 2) - 10 , 10, 30, 30)
slideButton.addTarget(self, action: "animationFunction:", forControlEvents: UIControlEvents.TouchUpInside)
slideButton.setImage(imageForSlideButton,forState: .Normal)
self.addSubview(slideButton)}
}
internal func animationFunction(sender: UIButton!) {
UIView.animateWithDuration(0.5, animations: { () -> Void in
self.frame.size.width -= 100
})
}
答案 0 :(得分:3)
将此添加到您的代码中,使用单例并发送实例
chrome.tabs.query({'active': true, 'lastFocusedWindow': true}, function (tabs) {
var url = tabs[0].url;
});
在其他课程中:
static var sharedInstance : blueFooterForImages?
override init(frame: CGRect) {
super.init(frame: frame)
blueFooterForImages.sharedInstance = self
//rest of init code....
}
确保blueFooterForImages.sharedInstance不是nil
(确保在执行此操作之前创建了blueFooterForImages实例)