2015-01-07 3 views
-1

Я хочу реализовать localNotification.It не перезагружать таблицу. Пожалуйста, помогите заблаговременно. Я добавляю элемент, а затем сохраняю элемент. он не перезагружает таблицу, он стал пустым. Мой отладчик не выполняет функцию перезагрузки данных.Локальное уведомление не называется

В Мой ViewController1.m

-(IBAction)save:(id)sender 
{ 
    NSDate *date=[datepicker date]; 
    NSString *taskString =task.text; 
    UILocalNotification *localnotification=[[UILocalNotification alloc]init]; 
    localnotification.fireDate=date; 
    localnotification.alertBody=taskString; 
    [email protected]"Show Me The Item"; 
    localnotification.timeZone=[NSTimeZone defaultTimeZone]; 
    localnotification.applicationIconBadgeNumber=[[UIApplication sharedApplication]applicationIconBadgeNumber]+1; 
    [[UIApplication sharedApplication]scheduleLocalNotification:localnotification]; 



    [[NSNotificationCenter defaultCenter] postNotificationName:@"reloadData" object:self]; 


    [self dismissViewControllerAnimated:YES completion:nil]; 

ViewController.m 

- (void)viewDidLoad { 
    [super viewDidLoad]; 
    [[NSNotificationCenter defaultCenter] addObserver:self 
              selector:@selector(reloadTable) 
               name:@"reloadData" 
               object:nil]; 

    // Do any additional setup after loading the view, typically from a nib. 
} 

- (void)didReceiveMemoryWarning { 
    [super didReceiveMemoryWarning]; 
    // Dispose of any resources that can be recreated. 
} 
-(IBAction)add:(id)sender 
{ 
    ViewController1 *sec=[[ViewController1 alloc]initWithNibName:@"ViewController1" bundle:nil]; 
    [self presentViewController:sec animated:YES completion:nil]; 
} 
-(NSInteger)numberOfSectionsInTableView:(UITableView *)tableView 
{ 
    return 1; 
} 

-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section 
{ 
    return [[[UIApplication sharedApplication ]scheduledLocalNotifications]count]; 
} 
-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath 
{ 
    static NSString *[email protected]"ViewController"; 
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier forIndexPath:indexPath]; 

    // Get list of local notifications 
    NSArray *localNotifications = [[UIApplication sharedApplication] scheduledLocalNotifications]; 
    UILocalNotification *localNotification = [localNotifications objectAtIndex:indexPath.row]; 

    // Display notification info 
    [cell.textLabel setText:localNotification.alertBody]; 
    [cell.detailTextLabel setText:[localNotification.fireDate description]]; 

    return cell; 


} 
-(void)reloadTable 
{ 
    [table reloadData]; 
} 
+0

Почему здесь вы используете уведомление. В моем понимании без уведомления вы можете перезагрузить таблицу. Вызовите напрямую функцию reloadTable – Puvanarajan

+0

моя таблица находится на другом контроллере. –

+0

@rohanthankur: Вы не регистрируетесь из уведомления из любого места в этом контроллере? –

ответ

0

Вы должны использовать NSNotificationCenter для этого. Он работает как радиоантенна. Во-первых, вы должны зарегистрироваться на этой станции в viewDidLoad, как это:

[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(reloadTable:) name:@"reloadData" object:nil]; 

А потом на вашем другом ViewController отправить этот радиосигнал, который будет получен всеми классами, что прислушивается к этой станции. Отправить сообщение вроде этого:

[[NSNotificationCenter defaultCenter] postNotificationName:@"reloadData" object:nil]; 

Теперь ваш контроллер ViewController перезагрузит данные по запросу.

+0

не работает ....... –

+0

Вызывается ли ваш '- (void) reloadTable'? Запишите что-нибудь в нем. Инициализирован ли ваш другой ViewController (тот, на котором вы хотите перезагрузить данные)? Это должно определенно работать, я использовал это много раз ... – markich

+0

не называется sir ji –

Смежные вопросы