Я хочу реализовать 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];
}
Почему здесь вы используете уведомление. В моем понимании без уведомления вы можете перезагрузить таблицу. Вызовите напрямую функцию reloadTable – Puvanarajan
моя таблица находится на другом контроллере. –
@rohanthankur: Вы не регистрируетесь из уведомления из любого места в этом контроллере? –