Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>I think delegation is the most appropriate method for this task. You should create a new protocol called <code>SubjectViewControllerDelegate</code> and add some methods like:</p> <pre><code>- (void)subjectViewController:(SubjectViewController*)controller didEditSubject:(Subject*)subject; - (void)subjectViewController:(SubjectViewController*)controller didDeleteSubject:(Subject*)subject; </code></pre> <p>SubjectViewController has a delegate property to keep weak reference to its delegate. It calls the delegate methods whenever a data is deleted or edited.</p> <p>CategoryViewController implements this protocol and sets itself as the delegate of SubjectViewController instance before pushing it to the navigation controller. In this methods you can either refresh the all table, or just update the rows that are changed.</p> <p><strong>UPDATE:</strong></p> <p>Assuming that you have only one section in CategoryViewController and keep the subjects in an <code>NSMutableArray</code>, you can use the codes similar to below for updating the relevant part of the table view.</p> <pre><code>- (void)subjectViewController:(SubjectViewController*)controller didEditSubject:(Subject*)subject{ NSInteger row; NSIndexPath* indexPath; NSArray* indexPaths; row = [self.subjects indexOfObject:subject]; indexPath = [NSIndexPath indexPathForRow:row inSection:0]; indexPaths = [NSArray arrayWithObject:indexPath]; [self.tableView reloadRowsAtIndexPaths:indexPaths withRowAnimation:UITableViewRowAnimationNone]; } - (void)subjectViewController:(SubjectViewController*)controller didDeleteSubject:(Subject*)subject{ NSInteger row; NSIndexPath* indexPath; NSArray* indexPaths; row = [self.subjects indexOfObject:subject]; indexPath = [NSIndexPath indexPathForRow:row inSection:0]; indexPaths = [NSArray arrayWithObject:indexPath]; [self.subjects removeObjectAtIndex:row]; [self.tableView deleteRowsAtIndexPaths:indexPaths withRowAnimation:UITableViewRowAnimationNone]; } </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
 

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