Fun with Objective-C part 2

Posted on

Another note to self on how the source works from my last article. I followed to the last part of the “Tutorial: Add Data” tutorial where I fiddled around with my main.storyboard and modified a few parts of my code (which aren’t included here because it’s really just the same as this article ( https://developer.apple.com/library/ios/referencelibrary/GettingStarted/RoadMapiOS/ThirdTutorial.html#//apple_ref/doc/uid/TP40011343-CH10-SW1 )

Anyway, the method I implemented according to the tutorial I thought … was something worth noting to myself.

Segue will carry either a Nil or some text data, depending on which button is pressed.

AddToDoItemViewController *source = [segue sourceViewController];   // point to our source of (item) values
ToDoItem *item = source.toDoItem;                                   // get our item value

Once we have our declarations for pointing to our source and a pointer to our source pointer we can check our Segue if there was any data passed back after the user has either pressed cancelled or save:

if (item != nil) {
    [self.toDoItems addObject: item];
    [self.tableView reloadData];
}

Put it all together the method looks like below.

-(IBAction)unwindToDoList:(UIStoryboardSegue *)segue {
    AddToDoItemViewController *source = [segue sourceViewController];   // point to our source of (item) values
    ToDoItem *item = source.toDoItem;                                   // get our item value
    
    if (item != nil) {
        [self.toDoItems addObject: item];
        [self.tableView reloadData];
    }
}

If the future me doesn’t understand this, then it means I should write better blogs because I’m lazy and an idiot.

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s