@@ -55,6 +55,7 @@ extension MessagingViewController: UITableViewDelegate, UITableViewDataSource {

}



// MARK - Nib Methods
func registerNibs(){
@@ -64,7 +65,7 @@ extension MessagingViewController: UITableViewDelegate, UITableViewDataSource {
tableView.registerNib(userMessage, forCellReuseIdentifier: "UserMessageCell")
}


//in
// MARK - Listeners
func textViewBeganEditing(){
//Flash red if over 140 count
@@ -87,19 +88,21 @@ extension MessagingViewController: UITableViewDelegate, UITableViewDataSource {
})
}, completion: nil)
}


if textView.frame.size.height < textView.contentSize.height {

let height = textView.contentSize.height
var frame = textView.frame

UIView.animateWithDuration(0.5, delay: 0.0, options: [], animations: { () -> Void in
frame.size.height = height + 10.00
self.textView.frame = frame

}, completion: nil)
}

textView.sizeToFit()
textView.layoutIfNeeded()
//
// if textView.frame.size.height > textView.contentSize.height {
//
// let height = textView.contentSize.height
// var frame = textView.frame
//
// UIView.animateWithDuration(0.5, delay: 0.0, options: [], animations: { () -> Void in
// frame.size.height = height + 10.00
// self.textViewContainerHeight.constant = frame.size.height
// print(self.textViewContainerHeight.constant)
// }, completion: nil)
// }
}
//MARK - TableView Delegate Methods
@@ -158,10 +161,14 @@ extension MessagingViewController: UITableViewDelegate, UITableViewDataSource {
if indexPath.row == messages.count - 1 {
if let generalCell = cell as? GeneralMessageCell {
generalMessageCellWillDisplay(generalCell, indexPath: indexPath)
tableView.scrollToBottom()

}

if let userCell = cell as? UserMessageCell {
userMessageCellWillDisplay(userCell, indexPath: indexPath)
tableView.scrollToBottom()

}
}
}
@@ -190,7 +197,7 @@ extension MessagingViewController: UITableViewDelegate, UITableViewDataSource {
NSNotificationCenter.defaultCenter().addObserver(self, selector: "keyboardWillShow:", name: UIKeyboardWillShowNotification, object: nil)
NSNotificationCenter.defaultCenter().addObserver(self, selector: "keyboardWillHide:", name: UIKeyboardWillHideNotification, object: nil)
NSNotificationCenter.defaultCenter().addObserver(self, selector: "textViewBeganEditing", name: UITextViewTextDidChangeNotification, object: nil)

textView.scrollEnabled = false
registerNibs()

tableViewOrientation()
@@ -0,0 +1,19 @@
//
// TableView.swift
// CoChat
//
// Created by Aaron B on 2/23/16.
// Copyright © 2016 Jerry. All rights reserved.
//
import UIKit

extension UITableView {
func scrollToBottom(animated: Bool = true) {
let row = self.numberOfRowsInSection(0)
if row > 0 {
self.scrollToRowAtIndexPath(NSIndexPath(forRow: row - 1, inSection:0), atScrollPosition: .Bottom, animated: animated)
}
}
}