그래서 두 개의 뷰 컨트롤러가 동시에 표시됩니다. 목표는 다음과 같습니다. 메뉴를 누르면 인덱스가 반환됩니다. 그러면 업데이트해야 할 다른 화면이 나타납니다. (메뉴)NSNotification userinfo는 누름 버튼을 누를 때 계속 누적됩니다.
func carbonTabSwipeNavigation(carbonTabSwipeNavigation: CarbonTabSwipeNavigation, didMoveAtIndex index: UInt) {
//NSLog("Did move at index: %ld", index)
//NSNotification to send data
NSNotificationCenter.defaultCenter().postNotificationName(NotificationNames.GetIndexCarbonKit, object: nil, userInfo: ["clickedIndex" : Int(index)])
}
컨트롤러 B (수신기)
제어기 A
override func viewWillAppear(animated: Bool) {
NSNotificationCenter.defaultCenter().addObserver(self, selector: #selector(SearchResults.didReceiveNotification(_:)), name: NotificationNames.GetIndexCarbonKit, object: nil)
}
func didReceiveNotification(notification: NSNotification) {
let index:Dictionary<String,Int> = notification.userInfo as! Dictionary<String,Int>
let messageFromNotification = index["clickedIndex"]
print(" SearchResults now shows index: \(messageFromNotification)")
}
내 문제는 다음입니다 :
나는 다음을 수행하고있는 사전있는 나는 인덱스를 A에서 B로 보내고 계속 스태킹합니다. 따라서 메뉴를 여러 번 누르면 내 결과는 다음과 같습니다.
SearchResults now shows index: Optional(0)
SearchResults now shows index: Optional(1)
SearchResults now shows index: Optional(1)
SearchResults now shows index: Optional(2)
SearchResults now shows index: Optional(2)
SearchResults now shows index: Optional(2)
SearchResults now shows index: Optional(3)
SearchResults now shows index: Optional(3)
SearchResults now shows index: Optional(3)
SearchResults now shows index: Optional(3)
SearchResults now shows index: Optional(1)
SearchResults now shows index: Optional(1)
SearchResults now shows index: Optional(1)
SearchResults now shows index: Optional(1)
SearchResults now shows index: Optional(1)
어떻게 마지막 색인 만 얻을 수 있습니까? 나는 다른 것들의 스택을 필요로하지 않는다.
감사합니다. 정보를 제공해 주셔서 감사합니다. 사전은 스태킹을 멈추지 않습니다. – SoundShock
수정 된 답변을 확인하십시오. viewDidLoad에서 호출해서는 안됩니다. – Dershowitz123
'func didReceiveNotification'은 옵저버를 추가 한 후에 만 호출되기 때문에 그렇게 할 수 없습니다. 따라서 NSNotificationCenter.defaultCenter(). addObserver (self, selector : #selector (SearchResults.didReceiveNotification (_ :)) ' – SoundShock