Commit f5487b02 by Olzhas Aldabergenov

chat keyboard and scrolling fixed

parent bf925785
......@@ -47,7 +47,7 @@
endingColumnNumber = "9223372036854775807"
startingLineNumber = "65"
endingLineNumber = "65"
landmarkName = "bind(nodes:)"
landmarkName = "bind(_:)"
landmarkType = "7">
</BreakpointContent>
</BreakpointProxy>
......
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<document type="com.apple.InterfaceBuilder3.CocoaTouch.XIB" version="3.0" toolsVersion="9532" systemVersion="15D21" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" useTraitCollections="YES">
<document type="com.apple.InterfaceBuilder3.CocoaTouch.XIB" version="3.0" toolsVersion="11201" systemVersion="15G1004" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" useTraitCollections="YES" colorMatched="YES">
<dependencies>
<deployment identifier="iOS"/>
<plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="9530"/>
<plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="11161"/>
<capability name="documents saved in the Xcode 8 format" minToolsVersion="8.0"/>
</dependencies>
<customFonts key="customFonts">
<mutableArray key="PT_Sans-Web-Bold.ttf">
<array key="PT_Sans-Web-Bold.ttf">
<string>PTSans-Bold</string>
<string>PTSans-Bold</string>
</mutableArray>
</array>
</customFonts>
<objects>
<placeholder placeholderIdentifier="IBFilesOwner" id="-1" userLabel="File's Owner"/>
......@@ -18,19 +17,16 @@
<autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/>
<subviews>
<label opaque="NO" userInteractionEnabled="NO" contentMode="left" text="Label" textAlignment="center" lineBreakMode="wordWrap" numberOfLines="0" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" translatesAutoresizingMaskIntoConstraints="NO" id="5es-8G-PFJ" userLabel="step">
<rect key="frame" x="20" y="20" width="560" height="21"/>
<fontDescription key="fontDescription" type="system" pointSize="17"/>
<color key="textColor" red="0.0" green="0.0" blue="0.0" alpha="1" colorSpace="calibratedRGB"/>
<color key="textColor" red="0.0" green="0.0" blue="0.0" alpha="1" colorSpace="custom" customColorSpace="sRGB"/>
<nil key="highlightedColor"/>
</label>
<label opaque="NO" userInteractionEnabled="NO" contentMode="left" text="Label" textAlignment="center" lineBreakMode="wordWrap" numberOfLines="0" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" translatesAutoresizingMaskIntoConstraints="NO" id="Ylo-Eb-ARy" userLabel="tipLabel">
<rect key="frame" x="20" y="61" width="560" height="21"/>
<fontDescription key="fontDescription" type="system" pointSize="17"/>
<color key="textColor" red="0.0" green="0.0" blue="0.0" alpha="1" colorSpace="calibratedRGB"/>
<color key="textColor" red="0.0" green="0.0" blue="0.0" alpha="1" colorSpace="custom" customColorSpace="sRGB"/>
<nil key="highlightedColor"/>
</label>
<textField opaque="NO" clipsSubviews="YES" contentMode="scaleToFill" contentHorizontalAlignment="left" contentVerticalAlignment="center" borderStyle="roundedRect" textAlignment="natural" minimumFontSize="17" translatesAutoresizingMaskIntoConstraints="NO" id="Kwb-av-9cJ" userLabel="GUID">
<rect key="frame" x="15" y="102" width="570" height="44"/>
<constraints>
<constraint firstAttribute="height" constant="44" id="4oD-g8-RYu"/>
</constraints>
......@@ -38,34 +34,31 @@
<textInputTraits key="textInputTraits"/>
</textField>
<textField opaque="NO" clipsSubviews="YES" contentMode="scaleToFill" contentHorizontalAlignment="left" contentVerticalAlignment="center" borderStyle="roundedRect" textAlignment="natural" minimumFontSize="17" translatesAutoresizingMaskIntoConstraints="NO" id="zpI-tj-1Ya" userLabel="RegsitrationCode">
<rect key="frame" x="15" y="154" width="570" height="44"/>
<fontDescription key="fontDescription" type="system" pointSize="17"/>
<textInputTraits key="textInputTraits"/>
</textField>
<button opaque="NO" contentMode="scaleToFill" contentHorizontalAlignment="center" contentVerticalAlignment="center" buttonType="roundedRect" lineBreakMode="middleTruncation" translatesAutoresizingMaskIntoConstraints="NO" id="Gf3-an-afz">
<rect key="frame" x="15" y="218" width="570" height="51"/>
<color key="backgroundColor" red="0.1058823529" green="0.45882352939999999" blue="0.73333333329999995" alpha="1" colorSpace="custom" customColorSpace="sRGB"/>
<color key="backgroundColor" red="0.095081739127635956" green="0.37402468919754028" blue="0.67706954479217529" alpha="1" colorSpace="custom" customColorSpace="sRGB"/>
<constraints>
<constraint firstAttribute="height" constant="51" id="v7D-C0-vSa"/>
</constraints>
<fontDescription key="fontDescription" name="PTSans-Bold" family="PT Sans" pointSize="17"/>
<state key="normal" title="Далее">
<color key="titleColor" white="1" alpha="1" colorSpace="calibratedWhite"/>
<color key="titleColor" red="1" green="1" blue="1" alpha="1" colorSpace="custom" customColorSpace="sRGB"/>
</state>
</button>
<button opaque="NO" contentMode="scaleToFill" contentHorizontalAlignment="center" contentVerticalAlignment="center" buttonType="roundedRect" lineBreakMode="middleTruncation" translatesAutoresizingMaskIntoConstraints="NO" id="zMr-Jb-Ez2">
<rect key="frame" x="15" y="284" width="570" height="51"/>
<color key="backgroundColor" red="0.3294117647" green="0.41568627450000001" blue="0.52549019610000003" alpha="1" colorSpace="custom" customColorSpace="sRGB"/>
<color key="backgroundColor" red="0.26219156384468079" green="0.33811080455780029" blue="0.45045208930969238" alpha="1" colorSpace="custom" customColorSpace="sRGB"/>
<constraints>
<constraint firstAttribute="height" constant="51" id="bhd-Hz-5nT"/>
</constraints>
<fontDescription key="fontDescription" name="PTSans-Bold" family="PT Sans" pointSize="17"/>
<state key="normal" title="Отмена">
<color key="titleColor" white="1" alpha="1" colorSpace="calibratedWhite"/>
<color key="titleColor" red="1" green="1" blue="1" alpha="1" colorSpace="custom" customColorSpace="sRGB"/>
</state>
</button>
</subviews>
<color key="backgroundColor" white="1" alpha="1" colorSpace="custom" customColorSpace="calibratedWhite"/>
<color key="backgroundColor" red="1" green="1" blue="1" alpha="1" colorSpace="custom" customColorSpace="sRGB"/>
<constraints>
<constraint firstAttribute="bottom" relation="greaterThanOrEqual" secondItem="zMr-Jb-Ez2" secondAttribute="bottom" constant="5" id="1Mq-VX-Mxs"/>
<constraint firstItem="Kwb-av-9cJ" firstAttribute="top" secondItem="Ylo-Eb-ARy" secondAttribute="bottom" constant="20" id="2Yu-B8-ktj"/>
......
......@@ -8,7 +8,7 @@
import UIKit
class BotViewController: UIViewController {
class BotViewController: UIViewController, UITableViewDataSource, UITableViewDelegate {
@IBOutlet weak var messageField: UITextField!
@IBOutlet weak var tableView: UITableView!
......@@ -19,6 +19,7 @@ class BotViewController: UIViewController {
weak var activeField: UITextField?
var messagesList : [BotResult] = []
var heightAtIndexPath = NSMutableDictionary()
override func viewDidLoad() {
super.viewDidLoad()
......@@ -31,14 +32,15 @@ class BotViewController: UIViewController {
self.circleButton.userInteractionEnabled = true
self.circleButton.addGestureRecognizer(tap)
addMessage("Здравствуйте! Я Ваш помощник на сайте Казахтелеком. Постараюсь ответить на большинство Ваших вопросов.", type: 0)
NSNotificationCenter.defaultCenter().addObserver(self,
selector: #selector(self.keyboardNotification(_:)),
name: UIKeyboardWillChangeFrameNotification,
object: nil)
initializeTap()
addMessage("Здравствуйте! Я Ваш помощник на сайте Казахтелеком. Постараюсь ответить на большинство Ваших вопросов.", type: 0)
}
func initializeTap() {
......@@ -99,7 +101,6 @@ class BotViewController: UIViewController {
func textFieldShouldReturn(textField: UITextField) -> Bool {
textField.resignFirstResponder()
self.tableView.scrollToBottom(true)
return true
}
......@@ -114,8 +115,23 @@ class BotViewController: UIViewController {
var botNodes : [BotNode] = []
botNodes.append(botNode)
botResult.nodes = botNodes
self.addMessage(botResult)
}
func addMessage(botResult: BotResult) {
self.tableView.beginUpdates()
self.messagesList.append(botResult)
self.tableView.reloadData()
let indexPath = NSIndexPath(forRow: (self.messagesList.count - 1), inSection: 0)
self.tableView.insertRowsAtIndexPaths([indexPath], withRowAnimation: UITableViewRowAnimation.Top)
self.tableView.endUpdates()
self.tableView.scrollToBottom(true)
}
func reloadTable() {
}
func numberOfSectionsInTableView(tableView: UITableView) -> Int {
......@@ -138,19 +154,13 @@ class BotViewController: UIViewController {
}
}
func reloadTable() {
self.tableView.reloadData()
}
func getChildNodes(id: Int) {
Facade.sharedInstance().childBot(String(id), onSuccess: { (botResult) in
if botResult.count != 0 {
self.messagesList.append(botResult)
self.tableView.reloadData()
self.addMessage(botResult)
} else {
self.addMessage("Извините, по вашему запросу ничего не нашлось", type: 0)
}
self.tableView.scrollToBottom(true)
}) { (error) in
AlertViewUtil.showErrorAlert(error, vc: self)
}
......@@ -165,22 +175,32 @@ class BotViewController: UIViewController {
self.messageField.text = ""
addMessage(messageStr, type: 1)
self.tableView.scrollToBottom(true)
Facade.sharedInstance().askBot(messageStr, onSuccess: { (botResult) in
if botResult.count != 0 {
self.messagesList.append(botResult)
self.tableView.reloadData()
self.addMessage(botResult)
} else {
self.addMessage("Извините, по вашему запросу ничего не нашлось", type: 0)
}
self.tableView.scrollToBottom(true)
}) { (error) in
AlertViewUtil.showErrorAlert(error, vc: self)
}
//dismissKeyboard()
}
func tableView(tableView: UITableView, estimatedHeightForRowAtIndexPath indexPath: NSIndexPath) -> CGFloat {
let height = self.heightAtIndexPath.objectForKey(indexPath)
if ((height) != nil) {
return CGFloat(height!.floatValue)
} else {
return UITableViewAutomaticDimension
}
}
func tableView(tableView: UITableView, willDisplayCell cell: UITableViewCell, forRowAtIndexPath indexPath: NSIndexPath) {
let height = cell.frame.size.height
self.heightAtIndexPath.setObject(height, forKey: indexPath)
}
}
extension UITableView {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment