Sunday, July 19, 2015

iOS Storyboard Part II - Notes From Apple Tutorial

The first part of the storyboard tutorial from Apple did include unwind segue, but most important thing to me was when Save was pressed, it was doing the same action as Exit / cancel on the screen. So, the main thing to learn is how to Save the data from the current controller itself before unwinding back. 

On thing to remind is that Assistant editor is powerful. Once a view controller is selected, its custom controller is shown side by side and just by control dragging the component, can add the properties to the class. 


Now, since on Save button press, opted to exit out, one can uncomment the method in the current view controller and assign the variables. 

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.

    self.favItemName = self.myfavName.text;
}

Now on the target controller to which unwinding is happening, the code can be added like below 

- (IBAction)unwindToList:(UIStoryboardSegue *)segue
{
    NewFavoriteViewController *favVC = [segue sourceViewController];
    NSString *favItemName = favVC.favItemName;
}


References:

No comments:

Post a Comment