         
     }
     
+    func labelHeight(res res:()-> Void){
+        if self.json?.count != 0{
+            let count = self.json!.count
+            for row in 0...count-1 {
+                let str = self.json![row]["message"].stringValue
+                let url = self.json![row]["user_icon"].string
+                if url != nil{
+                    heights.append(floor(TableCellLayout(str: str, w: self.view.bounds.size.width).h)+4)
+                }else{
+                    heights.append(floor(TableCellLayout(str: str, w: self.view.bounds.size.width).h)-8)
+                }
+                
+            }
+        }
+        res()
+    }
+    
+    
     func positionForBar(bar: UIBarPositioning) -> UIBarPosition {
         return UIBarPosition.TopAttached
     }
     
     func keyboardWillShow(notification: NSNotification){
         let userInfo = notification.userInfo!
-        let keyboardRect = (userInfo[UIKeyboardFrameEndUserInfoKey] as! NSValue).CGRectValue()
+        let keyboardScreenEndFrame = (userInfo[UIKeyboardFrameEndUserInfoKey] as! NSValue).CGRectValue()
         let myBoundSize: CGSize = UIScreen.mainScreen().bounds.size
-        let kbdLimit = myBoundSize.height - keyboardRect.size.height
-        let txtLimit = self.textField.frame.origin.y + self.textField.frame.height + 8.0
+        let txtLimit = textField.frame.origin.y + textField.frame.height + 112
+        let kbdLimit = myBoundSize.height - keyboardScreenEndFrame.size.height
+        
         if txtLimit >= kbdLimit {
-            self.scrollview.contentOffset.y = keyboardRect.size.height
-            
+            scrollview.contentOffset.y = txtLimit - kbdLimit
         }
     }
     

        
        Socket.on("post") {data, ack in
            if self.json != nil{
                self.json = JSON(self.json!.arrayObject! + JSON(data).arrayObject!)
                self.comLabel.text = "\(self.json!.count)"
                dispatch_async(dispatch_get_main_queue(), { () -> Void in
                    self.tableview.reloadData()
                    self.tableview.scrollToRowAtIndexPath(NSIndexPath(forRow: self.json!.count-1, inSection: 0), atScrollPosition: UITableViewScrollPosition.Bottom, animated: true)
                })
            }

        
        Socket.on("get") {data, ack in
            UIApplication.sharedApplication().networkActivityIndicatorVisible = false
            self.json = JSON(data)[0]["comments"]
            
            self.labelHeight(res:{
                dispatch_async(dispatch_get_main_queue(), { () -> Void in
                    if self.tableview != nil {
                        self.tableview.reloadData()
                        
                        if self.json?.count != 0{
                            self.tableview.scrollToRowAtIndexPath(NSIndexPath(forRow: self.json!.count-1, inSection: 0),
                                atScrollPosition: UITableViewScrollPosition.Bottom, animated: false
                            )
                            
                        }
                        self.comLabel.text = "\(self.json!.count)"
                    }
                })
            })
            if self.live_status! == true {
                self.Socket.emit("join", [
