diff --git a/P15-Decorating-Post-Cell/content.md b/P15-Decorating-Post-Cell/content.md index c875b3f..66a10c6 100755 --- a/P15-Decorating-Post-Cell/content.md +++ b/P15-Decorating-Post-Cell/content.md @@ -192,6 +192,15 @@ You can grab the exact color for the Label from the Action button using the colo +#One more thing... + +The Table View Cell is looking great - but there's one last option we should tweak. +We should turn off the _User Interaction_ for the Table View Cell. Often Table Views are used to display an overview of information and they allow the user to select a cell to receive more detailed information (such as the _Mail_ and the _Messages_ app on iOS). In _Makestagram_ however, we are displaying the entire information about a post directly within the cell. We provide some buttons for interaction, but nothing happens if a user selects and individual cell. Except that the cell color changes to a light gray which shall indicate that the cell has been selected - in our app that is very confusing. + +
+Turn of the _User Interaction_ for the Table View Cell, so that cells no longer get highlighted: +![image](deactivate_user_interaction.png) + #Testing it all together If you run your app, with all of these changes in place, you should see a timeline that looks similar to this one: diff --git a/P15-Decorating-Post-Cell/deactivate_user_interaction.png b/P15-Decorating-Post-Cell/deactivate_user_interaction.png new file mode 100644 index 0000000..a3ad2c4 Binary files /dev/null and b/P15-Decorating-Post-Cell/deactivate_user_interaction.png differ diff --git a/P15-Decorating-Post-Cell/deactivate_user_interaction.sketch b/P15-Decorating-Post-Cell/deactivate_user_interaction.sketch new file mode 100644 index 0000000..10fa121 Binary files /dev/null and b/P15-Decorating-Post-Cell/deactivate_user_interaction.sketch differ diff --git a/P16-Implementing-Likes/.DS_Store b/P16-Implementing-Likes/.DS_Store index 5008ddf..0073025 100644 Binary files a/P16-Implementing-Likes/.DS_Store and b/P16-Implementing-Likes/.DS_Store differ diff --git a/P16-Implementing-Likes/content.md b/P16-Implementing-Likes/content.md index c763dfd..761bfb1 100755 --- a/P16-Implementing-Likes/content.md +++ b/P16-Implementing-Likes/content.md @@ -242,4 +242,37 @@ A short side note: We haven't discussed the `// MARK:` feature of Xcode yet. It If you include `// MARK:' sections in your source code, they will show up as headers in this view - great for navigating through more complex classes! -With all of the queries in place, we should think about from where we want to call them, next! +With all of the queries in place, we should think about how we want tie them into the rest of our code, next! +Where should we place the code that adds and removes likes from `Post` objects? + +We're going to add it directly to the `Post` class and you'll shortly see why! + +#Extending the Post class + +In most object oriented programs we wan't to couple the information that an object stores along with its behavior. If I have access to a `Post` object I would like to be able to like it or unlike it with a simple method call. I would also like to be able to access of all of the likes of a `Post` directly through a simple method call. + +Now we're going to add this functionality to the `Post` class. It consists of two different parts: + +1. Storing likes +2. Adding / removing likes + +Let's start with storage. **Why do we want to store likes in the first place?** + +##Storing likes + +We want to avoid to perform network requests, every single time we want to access the likes that belong to a post. Instead, similar to the post's image, we want to cache the information we have fetched. + +Towards the end of this tutorial we will add a pull-to-refresh mechanism that allows users to refresh the timeline. We want to cache all information until such a refresh happens. + +In which format should we store likes? For our purposes the best format is an array of users that have liked a certain post. + +Just as with the image of a `Post`, we won't load all of the likes directly with the timeline query. Instead, we will load them lazily as soon as a post is displayed. This means, we once again need to deal with data is available _asynchronously_. Our favorite tool for such cases is the `Dynamic` wrapper - as we discussed in detail when we implemented the image download. + +With all this in mind, let's add the `likes` property to the `Post` class. + +
+Add the following property to the `Post` class: + + var likes = Dynamic<[PFUser]?>(nil) + +We create the `likes` property as a _dynamic_, _optional_ array of `PFUser` - now that's a mouthful! However, we've used all of these concepts before. We make the property `Dynamic` so that we can listen to changes and update our UI after we've downloaded the likes for a post. We make it _optional_, because before we've downloaded the likes this property will be `nil`.