2014-04-11 4 views
1

제 코드에는 약 012+가 약 NSNotification입니다.NSNotificationCreation은 응용 프로그램 성능에 영향을 줍니까?

[[NSNotificationCenter defaultCenter] addObserver....]; 
[[NSNotificationCenter defaultCenter] postNotificationName...]; 

등록 및 화재 알림 기능을 많이 사용하면 응용 프로그램 성능에 영향을 줍니까?

+0

이는 처리 방법에 따라 다릅니다. – Rajesh

+0

사용 후 특정 알림을 제거해야합니다. 그렇지 않으면 twise 이상을 호출 ... 동일한 작업을 수행하는 데 Custom Delegate 프로토콜을 사용하는 것이 좋습니다. NSNotification 센터 대신 훨씬 좋습니다. –

+0

@ NitinGohel의 포인트를 확장하려면 to-many 통신에는 'NSNotificationCentre'를 사용하고, to-one에는 대리자 또는 콜백을 사용하십시오. 여기의 관계는 무엇입니까? 또한 중복 된 알림을 전송할 수있는 경우 [NSNotificationQueue'] (https://developer.apple.com/library/ios/documentation/cocoa/reference/foundation/Classes/NSNotificationQueue_Class)의 병합 기능을 살펴볼 수 있습니다. /Reference/Reference.html) –

답변

2

이것은 당신이 당신의 viewWillAppear에 추가하고 viewWillDisappear에 제거됩니다 NSNotification에 대한라고 twice or more times..

가장 좋은 방법 bcoz 당신의 NSNotification 순수하게 한 후 그 효과를 처리하여 code.if에 NSNotificationCenter을 처리하는 방법에 달려있다. 톨로가 자동적으로 당신을 위해이 작업을 수행 - 당신은 tolo

가장 큰 장점을 살펴해야한다 대신 NSNotificationCenter

+0

iOS 7에서 발생하는 [viewMightAppear :] (http://blog.supertop.co/post/80781694515/viewmightappear) 증후군을주의하십시오. – 0xced

+0

언제 앱에서 사용하고 싶습니까? – Rajneesh071

0

은 관찰자를 추가/제거하는 방법에 대한 걱정하지 않아도됩니다.

ps. 옵저버를 제거하지 않으면 유지주기 및 메모리 누수가 발생할 수 있습니다.

관련 문제