Note that there are some explanatory texts on larger screens.

plurals
  1. PONSNotificationCenter adds all instances as observer
    primarykey
    data
    text
    <p>So i have a class that adds itself as observer in NSNotificationService on init and on dealloc removes itself from NSNotificationCenter.</p> <p>Everything works great, i post notification and receive it once and with correct object.</p> <p>Then i did a loop and added three views. Each view got called init once, all views added itself as observer.</p> <p>Now when i post notification, each view receives its notification three times! (9 in total)</p> <p>So i moved my add observer to another method and called it only on two views (from those three).</p> <p>Now each view got called twice (three views called two times, 6 total) although third instance was not even added as observer (watched metgod, did not get called as expected).</p> <p>Now i removed loop and created three views. And added only one as observer. All three got called...</p> <p>Is this known issue or did i find something new?</p> <p>XCode 4.6 iOS 6.1</p> <p>UPDATE---------------</p> <p>Problem is, that my View is actually just one instance.</p> <p>This code produces three views that are all the same one view.</p> <pre><code>CustomViewController * hw1 = [[CustomViewController alloc] init]; [hw1 setupWithFrame:CGRectMake( contentScrollView.frame.size.width * 0 + contentScrollView.frame.size.width/2 - 250 , contentScrollView.frame.size.height / 2 - 250,500,500)]; [contentScrollView addSubview:hw1.view]; CustomViewController * hw2 = [[CustomViewController alloc] init]; [hw2 setupWithFrame:CGRectMake( contentScrollView.frame.size.width * 1 + contentScrollView.frame.size.width/2 - 250 , contentScrollView.frame.size.height / 2 - 250,500,500)]; [contentScrollView addSubview:hw2.view]; CustomViewController * hw3 = [[CustomViewController alloc] init]; [hw3 setupWithFrame:CGRectMake( contentScrollView.frame.size.width * 2 + contentScrollView.frame.size.width/2 - 250 , contentScrollView.frame.size.height / 2 - 250,500,500)]; [contentScrollView addSubview:hw3.view]; </code></pre> <p>Changing content in hw1, changes content in hw2 and hw3.</p> <p>SetupWithFrame is just a method that allocates and adds subviews of defined frame.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload