1

I have searched alot, But I did not find the solution and don't Know why is this happening.

I am Creating and scheduling local notification and showing list of notifications in a table view. As my application launches the local notification are creating and showing in the table. But After pressing the home button the application will enter in the background and notifications are firing on their respective time set. After firing they also removed from the system array

[[UIApplication sharedApplication] scheduledLocalNotifications]

As I open the application again it become active and will enter in foreground state. and In app delegate method is calling

 - (void)applicationDidBecomeActive:(UIApplication *)application
        {
            AnotherClass *class = [[AnotherClass alloc]init];
               [class afterBecomeActive];
        }

here is the AnotherClass Implementation. In Which I have to refresh the table..

 -(void) afterBecomeActive
    {
        [tableView reloadData];
    }

That table view is not reloading data or refreshing the data, contains the list of Local Notifications. All notifications are showings as it is and delegates methods are not calling. Please help.

rmaddy
  • 314,917
  • 42
  • 532
  • 579
Stunner
  • 532
  • 3
  • 16
  • 2
    In `applicationDidBecomeActive` of appDelegate you are creating the new instance of `AnotherClass`. That will reload the tableview of different instance. – Prasad Devadiga Aug 09 '13 at 12:42

3 Answers3

1

Do this in the class containing the tableView. Ask to be notified about ApplicationDidBecomeActive.

- (void)awakeFromNib {

    [[NSNotificationCenter defaultCenter] addObserver:self
                                             selector:@selector(applicationDidBecomeActive:)
                                                 name:UIApplicationDidBecomeActiveNotification object:nil];
}

When you are notified, reload the table.

- (void)applicationDidBecomeActive:(NSNotification *)notification {

    [self.tableView reloadData];
}

The code in the app delegate can be removed. The others are correct: it's just allocating a new view controller sending it a message and throwing it away.

danh
  • 62,181
  • 10
  • 95
  • 136
0

In applicationDidBecomeActive you are creating new object of that class and just calling reloadData method of table. But you haven't initialize table for this object. So, this is the reason for not calling delegate methods of tableView. For doing so you need to create that object global in Appdelegate or you can store that object in NSUserDefault while leaving from app, and retrive that object when you back to app.

Trup
  • 635
  • 5
  • 17
0

You need to cancel notification which received by you.

Write following code:

- (void)application:(UIApplication *)application didReceiveLocalNotification:(UILocalNotification *)notification
{

    [[UIApplication sharedApplication] cancelLocalNotification:notification]; // this is code for cancel specific notification.

    application.applicationIconBadgeNumber = [[UIApplication sharedApplication]applicationIconBadgeNumber]-1; /// here you need  to decrease badge number if you have to added. 
}

And then after reload you UITableView.

Also read This Question, it might be helpful for your.

Community
  • 1
  • 1