채팅 탭바 클릭하면 채팅 리스트 출력
//
// ChatRoomsViewController.swift
// FreeTalk
//
// Created by stayfoolish on 2018. 9. 16..
// Copyright © 2018년 stayfoolish. All rights reserved.
//
import UIKit
import Firebase
class ChatRoomsViewController: UIViewController,UITableViewDelegate,UITableViewDataSource {
@IBOutlet weak var tableview: UITableView!
var uid : String!
var chatrooms : [ChatModel]! = []
override func viewDidLoad() {
super.viewDidLoad()
self.uid = Auth.auth().currentUser?.uid
self.getChatroomsList()
// Do any additional setup after loading the view.
}
func getChatroomsList(){
Database.database().reference().child("chatrooms").queryOrdered(byChild: "users/"+uid).queryEqual(toValue: true).observeSingleEvent(of: DataEventType.value, with: {(datasnapshot) in
for item in datasnapshot.children.allObjects as! [DataSnapshot]{
if let chatroomdic = item.value as? [String:AnyObject]{
let chatModel = ChatModel(JSON: chatroomdic)
self.chatrooms.append(chatModel!)
}
}
self.tableview.reloadData()
})
}
func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
return self.chatrooms.count
}
func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
let cell = tableView.dequeueReusableCell(withIdentifier: "RowCell", for:indexPath)
return cell
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
// Dispose of any resources that can be recreated.
}
/*
// MARK: - Navigation
// In a storyboard-based application, you will often want to do a little preparation before navigation
override func prepare(for segue: UIStoryboardSegue, sender: Any?) {
// Get the new view controller using segue.destinationViewController.
// Pass the selected object to the new view controller.
}
*/
}
'Swift > firebase' 카테고리의 다른 글
스위프트 파이어베이스 카카오톡 #16 [ 메세지 보낸 시간 TimeStamp ] (0) | 2018.09.18 |
---|---|
스위프트 파이어베이스 카카오톡 #15 [ 대화방 리스트(Chat Room List - 2) 만들기 ] swift firebase (0) | 2018.09.17 |
스위프트 파이어베이스 카카오톡 #13 [ 말풍선 Chat Bubble2 만들기 ] swift firebase (0) | 2018.09.15 |
스위프트 파이어베이스 카카오톡 #12 [ 말풍선 Chat Bubble 만들기 ] swift firebase (0) | 2018.09.14 |
스위프트 파이어베이스 카카오톡 #11 [ 메세지 나타내기 ] swift firebase (0) | 2018.09.13 |