show feedConversations in FeedConversationsViewController

This commit is contained in:
nixzhu
2015-10-12 12:11:44 +08:00
committed by nixzhu
parent 28f06ffc18
commit d8fcc12e1e
3 changed files with 27 additions and 5 deletions
@@ -52,9 +52,8 @@ class ConversationsViewController: UIViewController {
}
lazy var conversations: Results<Conversation> = {
//return self.realm.objects(Conversation).sorted("updatedUnixTime", ascending: false)
// let predicate = NSPredicate(format: "type = %d", ConversationType.OneToOne.rawValue)
return self.realm.objects(Conversation).sorted("updatedUnixTime", ascending: false)
let predicate = NSPredicate(format: "type = %d", ConversationType.OneToOne.rawValue)
return self.realm.objects(Conversation).filter(predicate).sorted("updatedUnixTime", ascending: false)
}()
struct Listener {
@@ -7,11 +7,19 @@
//
import UIKit
import RealmSwift
class FeedConversationsViewController: UIViewController {
@IBOutlet weak var feedConversationsTableView: UITableView!
var realm: Realm!
lazy var feedConversations: Results<Conversation> = {
let predicate = NSPredicate(format: "type = %d", ConversationType.Group.rawValue)
return self.realm.objects(Conversation).filter(predicate).sorted("updatedUnixTime", ascending: false)
}()
let feedConversationCellID = "FeedConversationCell"
override func viewDidLoad() {
@@ -19,8 +27,11 @@ class FeedConversationsViewController: UIViewController {
title = "Feeds"
realm = try! Realm()
feedConversationsTableView.registerNib(UINib(nibName: feedConversationCellID, bundle: nil), forCellReuseIdentifier: feedConversationCellID)
feedConversationsTableView.rowHeight = 80
feedConversationsTableView.tableFooterView = UIView()
}
}
@@ -29,11 +40,14 @@ class FeedConversationsViewController: UIViewController {
extension FeedConversationsViewController: UITableViewDataSource, UITableViewDelegate {
func tableView(tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
return 15
return feedConversations.count
}
func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {
let cell = tableView.dequeueReusableCellWithIdentifier(feedConversationCellID) as! FeedConversationCell
if let conversation = feedConversations[safe: indexPath.row] {
cell.configureWithConversation(conversation)
}
return cell
}
}
@@ -24,5 +24,14 @@ class FeedConversationCell: UITableViewCell {
// Configure the view for the selected state
}
func configureWithConversation(conversation: Conversation) {
//self.conversation = conversation
//countOfUnreadMessages = countOfUnreadMessagesInConversation(conversation)
nameLabel.text = conversation.withGroup?.withFeed?.body
}
}