Raywenderlich.com Table Views Course Part 2

 After a brief Staycay (one night away) I am back to continue with TableViews! I may possibly complete this course today. Putting the notes on A3 paper really works, with this more for stuff I just need to make sense of at the time - talking aloud if you will. 

Let's recap what I made a note of on the A3 paper so far...


What are they?

  • Like fancy vertical stack views!
  • TVs are filled with 'cells'
  • The prototype cells are there to be used (built in the system) but you can also make custom ones
  • The Table View Controller - use this rather than a TV if you the know the WHOLE screen is going to be a TV basically
Properties

  • 'Read me' - the project from Catie to work with
  • Each TV is an instance of a TV class
  • The one essential property is the DATA SOURCE. This is not a special type but it has to conform to a protocol.
  • This protocol has two methods: 1) number of rows in section, 2) cell for row at index path
  • 1) Is easy - it is just an Int - a number to be returned. 2) Is more complex - needs a local constant to pass data into; a custom data struct (model) is best to then be accessed for this

Dequeuing

  • TV reuses cells - it shows as many as are needed
  • There is a special func for dequeue (dequeueResuableCell)
  • Identifier - what type of prototype cell we want; Index path - what cell and section the row goes into
  • The above need to be made clear in the code basically
Navigate to Detail View

  • Using a NC to embed the TVC into!
  • Segues - from the cell (with the custom name) to the new 'Detail' VC - this will be for taking there AND back again
  • @IBSegueAction needed 
  • Custom VC and code needed for this

Reload Data
  • Functions needed in model - specific ones for saving and loading data
  • ImagePickerController - conform to delegates (as an extension first) in the DetailVC. 
  • Accessing camera and saving images - need option on p-list (privacy)

SO, quite a few elements! MOST of this makes sense so far. Of course the more complex bits will need my 'consolidation' to make full sense of. 

Let's crack on!

Custom Table Cells

OK, this was complicated! A LOT of settings needed changing for this - a big session this one!

So for the challenge, I needed a LOT of help with. Very tricky and a lot to remember! Again, the consolidation will be the only way to actually learn and remember this. 

Static Table View

This is opposed to the default 'dynamic' cells...

Some extension code needed in the DetailViewController (for the text field bit...)

extension DetailViewController: UITextViewDelegate {

        func textViewDidEndEditing(_ textView: UITextView) {

            textView.resignFirstResponder()

        }

    

}


As with a lot of the course, the code is complex but Catie makes it as clear as she can. Recurring themes - conforming to delegate and adding in code to the DetailViewController.  Challenge is now to make new Static Table View but I'm not confident...

Right the challenge is to have a new table view, once 'new book' is added. The idea is to have room to type in new title and author for a book, and the select an image functionality from before. Static view too. I'll give it a go!

Troubleshooting breakthrough! Fatal error - out of range...It was a segue that I had returning back. Didn't like it!

Add multiple sections

Again, usual level of complication but just about making sense. 

*A note about constraints. Catie's way is cool but sometimes it just complicates things. I have gone back to the old-school way of pinning around the edges for the image and having the text right in the middle for and vert, as that neatly organises it. 

That's part 2 of 3 done! Part 2 definitely MUCH harder but this is good. When I do my consolidation, I will make much more sense of it then.


Comments

Popular posts from this blog

Coursera Introduction to Programming in Swift - Part 4