Note that there are some explanatory texts on larger screens.

plurals
  1. PONSNotificationCenter receive event method is executing multiple times
    text
    copied!<p>I am basically a Java developer and recently assigned a task on objective C (iPhone).</p> <p>I have started coding in the language. but while implementing the NSNotificationCenter I am having very strange <strong>problem</strong>.</p> <p>It is very difficult to explain my problem.</p> <p>My class A is having one global variable named <strong>array</strong> of type <strong>NSMutableArray</strong> Pointer. class's init method looks something like</p> <pre><code>- (id) init { if(self = [init]) { [NSNotificationCenter defaultCenter] addObserver:self @selector(successLogin) name:"successLogin" object:nil]; [NSNotificationCenter defaultCenter] addObserver:self @selector(failureLogin) name:"failureLogin" object:nil]; ... &lt;some code&gt; } </code></pre> <p>recieve event method looks like</p> <pre><code>- (void) successLogin: (NSNotification * ) notification { ... &lt;some code of writing data to db using **array**&gt; [self showSuccessAlert]; // it is showing UIAlert } </code></pre> <p>The sendEvent method (of other class B) is having code something like </p> <pre><code>[[NSNotificationCenter defaultCenter] postNotificationName:@"successLogin" object:nil]; </code></pre> <p>The class A is having one button "<strong>Validate</strong>" which calls class B's method and validate the user id and password entered by the user. it notify the observer if login is successful and observer is then Adding the login info to the db. The application allows to update db for 5 different login. (userid &amp; password)</p> <p>it works if I enter 1st record. when I add one more login info, the notification alert comes for twice. When I add one more it comes for thrice and so on. Also it updates db with the value of array which was at the time of 1st record addition</p> <p>but when I enter 1st record and quit the application (by <strong>removing the application from minimize list of iPhone as well as Simulator</strong>) and again run it and tries to add second record. It adds it correctly. so for 5 additions I have to repeat the above cycle which is of course not conveniently for user.</p> <p>Please help me to drag me out from this problem.</p>
 

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