버튼이있는보기 컨트롤러가 있습니다. 버튼을 누를 때 그렇게 같이 관찰자를 추가 NSNotificationCenter : 스위프트에서 옵저버 제거
func buttonPress(sender:UIButton){
NSNotificationCenter.defaultCenter().addObserverForName("buttonPressEvent", object:nil, queue:nil, usingBlock:{(notif) -> Void in
// code
})
}
는 I이 뷰 컨트롤러를 해제 한 다음에 돌아가서
//code
회 실행 버튼을 누르면. 나가서 다시 돌아 오면
//code
이 세 번 실행됩니다.
Observer를 다시 추가하기 전에 Observer를 제거하면이 코드가 두 번 실행되지 않습니다.
NSNotificationCenter.defaultCenter().removeObserver(self, name:"buttonPressEvent", object:nil)
그러나이 밤은 가공 : Ive gone through the documentation here와 필자는 그냥 관찰자를 추가 할 경우 위의 코드 줄을 추가했습니다.
어디서 잘못 알 수 있습니까?
내 문제가 해결되었습니다 - 많은 감사합니다! – Jimmery