Angela Yu Xcode 12 Course - Part 22 (lectures 198 to 201)
Yes, this time I AM managing two entries in a day! My aim is to complete the rest of this flash chat/Firebase course. It's doable. Let's do it!
Start Time - 13:06
Logging In
Before I start the video, just a note about the current project. There is a separate view controller for each screen - each separate one from the main storyboard. Something I've missed before is the links between these including segues.
For the challenge I've used the same code as before -
Start Time - 13:06
Logging In
Before I start the video, just a note about the current project. There is a separate view controller for each screen - each separate one from the main storyboard. Something I've missed before is the links between these including segues.
For the challenge I've used the same code as before -
Auth.auth().signIn(withEmail: emailTextfield.text!, link: passwordTextfield.text!) { (user, error) in
if error != nil {
print(error!)
} else {
print("Login success!")
self.performSegue(withIdentifier: "goToChat", sender: self)
}
}
That was easy and logical enough. Cool! It basically means we have built in error handling code for both registering and logging in to the app now.
Table Views
Misleading name - it is not a table because it does NOT have rows and columns! It is actually a LIST just with ROWS!
You see them all the time
So in our project, we have put in the table view and then the bar items.
With the below, all the constraints etc. have been done. This is how it looks on the main storyboard whereas the above is in the actual app when it is running.
class ChatViewController: UIViewController, UITableViewDelegate, UITableViewDataSource
So two more delegates are put in to be conformed to - for actually using the bits in the table view.
Another thing is the errors due to protocol expectations...
OK an explanation of how the cells work:
OK 8 cells fill the screen. When scrolling down, the one that is cell 9 is actually what cell 1 was. So reusing them each time. Cells are re-used basically.
Another cool thing - Angela has designed what the view is for each cell! This is in a separate .xib file.
It has an identifier and links to a class. CustomMessageCell.
Something about creating a new class - new cocoa touch class file needed. Choose the subclass of (table view cell in this case).
Right so created a new one (xib box selected) and then two files exist - one for the class file (like a swift file) and one for the xib - design file.
To set up a table view you need to specify the number of cells you want and what ones you want displayed.
Right so two methods created -
//TODO: Declare cellForRowAtIndexPath here:
func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
let cell = tableView.dequeueReusableCell(withIdentifier: "customMessageCell", for: indexPath) as! CustomMessageCell
let messageArray = ["First Message", "Second Message", "Third Message"]
cell.messageBody.text = messageArray[indexPath.row]
return cell
}
//TODO: Declare numberOfRowsInSection here:
func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
return 3
}
For the first one, a lot of code needed but most is with swift autocomplete.
*Issue with running the app - been trouble shooting for a few minutes or so...
Update - gone over it and over and no idea!!!
YES! Finally - my mistake was that I had 'link' as the argument name instead of 'password'. This was because I copied and pasted the same code as before without actually checking it was ALL applicable. Lesson learned! Going to do the last couple of bits for now - not the whole project yet!
Finish Time - 14:30 (approx 1 hour - can't count all of that troubleshooting to be fair)
Well, it works! I'm doing well with this. I'm chuffed I identified the error in the end - having looked through the Q&A, it wasn't a capital letter error or anything like that. It does show you how careful you need to be - it wasn't actually a copy and paste error for that part but a typing mistake. Also, I didn't check with the simulator if it was working at THAT point. So lesson learned! Next time, possibly tomorrow, I will be completing the rest of this project!
Comments
Post a Comment