我有以下Singleton
class SharingManager{
var smallBigText : String = "KLANG!"
static let sharedInstance = SharingManager()
}
我用它来设置以下UILabel
@IBOutlet weak var kleinGrossLabel: UILabel!
我在ViewController
:
override func viewWillAppear(animated: Bool) {
super.viewWillAppear(animated)
self.kleinGrossLabel.text = SharingManager.sharedInstance.smallBigText
}
我在SharingManager.sharedInstance.smallBigText
类的实例方法中重置了SoundEvent
:
class SoundEvent {
var text:String
var duration:Double
init(text: String, duration: Double){
self.text = text
self.duration = duration
}
func startEvent(){
SharingManager.sharedInstance.smallBigText = self.text
}
func getDuration() -> Double{
return self.duration
}
}
当我运行应用程序时,UILabel
文本仍为“KLANG”,并且永远不会更改。
当我在以下函数中调用startEvent
时应该更改它:
func playEvent(eventIndex : Int){
if (eventIndex < 2){
let currEvent = self.eventArray[eventIndex]
currEvent?.startEvent()
let nextIndex = eventIndex + 1
//NSTimer.scheduledTimerWithTimeInterval(0.4, target: SomeClass.self, selector: Selector("someClassMethod"), userInfo: nil, repeats: true)
NSTimer.scheduledTimerWithTimeInterval((currEvent?.duration)!, target: self, selector: Selector("playEvent:"), userInfo: NSNumber(integer: nextIndex), repeats: false)
}
else if (eventIndex==2){
self.eventArray[eventIndex]?.startEvent()
NSTimer.scheduledTimerWithTimeInterval(0.4, target: self, selector: Selector("sentenceDidFinish"), userInfo: nil, repeats: false)
}
else{
//Do Nothing
}
}
我在ViewController
var s1:Sentence = Sentence(type: "S3")
s1.start()
Sentence
课程中的内容是:
func start(){
self.playEvent(0)
}
不知怎的,它打破了这个逻辑流,或者如果预期的事件序列正在执行,那么我在更改共享的Singleton资源{{1}时实际上并没有改变UILabel
的文本。 } var
为清楚起见,所有主要smallBigText
https://gist.github.com/anonymous/07542f638fc5b9a3c4e9