Please tell me how to update Array before exiting TableViewController

.h file

 @interface DaysTableViewController : UITableViewController{ NSArray * indexPathArray; IBOutlet UITableView *tableViewList; } 

.m file

 - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{ UITableViewCell *cell = [tableView cellForRowAtIndexPath:indexPath]; cell.accessoryType = UITableViewCellAccessoryCheckmark; indexPathArray = [tableViewList indexPathsForSelectedRows]; } - (void)tableView:(UITableView *)tableView didDeselectRowAtIndexPath:(NSIndexPath *)indexPath{ UITableViewCell *cell = [tableView cellForRowAtIndexPath:indexPath]; cell.accessoryType = UITableViewCellAccessoryNone; indexPathArray = [tableViewList indexPathsForSelectedRows]; } 
  • what is the exit? - Max Mikheyenko
  • @MaxMikheyenko - this is when you select the days when the alarm clock should sound and exit the list of days, if you don’t understand, see step 5 here - before exiting you need to update the array - the question how to do it, tried so - (void)viewWillDisappear{ NSLog(@"%@", indexPathArray); [tableViewList reloadData]; } (void)viewWillDisappear{ NSLog(@"%@", indexPathArray); [tableViewList reloadData]; } (void)viewWillDisappear{ NSLog(@"%@", indexPathArray); [tableViewList reloadData]; } but nothing advertises on exit - Void

1 answer 1

If you understand correctly, you need to transfer data to another controller before exiting with the view. You can for example use the method:

 - (void)viewWillDisapper { [super viewWillDisapper]; [self.delegate setSelectedRows:tableViewList. indexPathsForSelectedRows]; // заметим, что их не нужно даже хранить в промежуточной переменной } 

Here the delegate is the recipient of the data. But in fact, you need to thoroughly understand how MVC is organized in CocoaTouch, for example, to download examples from the Apple website, or to read the simplest articles on data transfer between controllers. Without understanding MVC, it’s difficult to come up with the right decision.