Search Friend

This commit is contained in:
kevinzhow
2015-03-28 03:37:56 +08:00
parent 012e31ff88
commit f30a9e22fe
5 changed files with 236 additions and 3 deletions
+12
View File
@@ -8,6 +8,7 @@
/* Begin PBXBuildFile section */
0A5D83941AC5D3C8000045BF /* YepTabBarController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0A5D83931AC5D3C8000045BF /* YepTabBarController.swift */; };
0A5D83991AC5D91E000045BF /* ContactsSearchTableViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0A5D83981AC5D91E000045BF /* ContactsSearchTableViewController.swift */; };
0A8F54B11AB67D11004AD60E /* AppDelegate.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0A8F54B01AB67D11004AD60E /* AppDelegate.swift */; };
0A8F54B61AB67D11004AD60E /* Main.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = 0A8F54B41AB67D11004AD60E /* Main.storyboard */; };
0A8F54B81AB67D11004AD60E /* Images.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = 0A8F54B71AB67D11004AD60E /* Images.xcassets */; };
@@ -88,6 +89,7 @@
/* Begin PBXFileReference section */
0A5D83931AC5D3C8000045BF /* YepTabBarController.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; name = YepTabBarController.swift; path = ViewControllers/TabBar/YepTabBarController.swift; sourceTree = "<group>"; };
0A5D83981AC5D91E000045BF /* ContactsSearchTableViewController.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; name = ContactsSearchTableViewController.swift; path = ViewControllers/Contacts/Search/ContactsSearchTableViewController.swift; sourceTree = "<group>"; };
0A8F54AB1AB67D11004AD60E /* Yep.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = Yep.app; sourceTree = BUILT_PRODUCTS_DIR; };
0A8F54AF1AB67D11004AD60E /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = "<group>"; };
0A8F54B01AB67D11004AD60E /* AppDelegate.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AppDelegate.swift; sourceTree = "<group>"; };
@@ -204,6 +206,14 @@
name = TabBar;
sourceTree = "<group>";
};
0A5D839A1AC5D923000045BF /* Search */ = {
isa = PBXGroup;
children = (
0A5D83981AC5D91E000045BF /* ContactsSearchTableViewController.swift */,
);
name = Search;
sourceTree = "<group>";
};
0A8F54A21AB67D11004AD60E = {
isa = PBXGroup;
children = (
@@ -311,6 +321,7 @@
isa = PBXGroup;
children = (
5023DE291AB685BA00B3EE96 /* ContactsViewController.swift */,
0A5D839A1AC5D923000045BF /* Search */,
);
name = Contacts;
sourceTree = "<group>";
@@ -820,6 +831,7 @@
502AE52B1AB819AF005BD199 /* YepConfig.swift in Sources */,
503315A01AC126100008A209 /* MessageToolbar.swift in Sources */,
502AE5531AB93215005BD199 /* ProfileFooterCell.swift in Sources */,
0A5D83991AC5D91E000045BF /* ContactsSearchTableViewController.swift in Sources */,
5023DE521AB6C51300B3EE96 /* CGRect+Yep.swift in Sources */,
);
runOnlyForDeploymentPostprocessing = 0;
+2 -2
View File
@@ -1,7 +1,7 @@
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<document type="com.apple.InterfaceBuilder3.CocoaTouch.Storyboard.XIB" version="3.0" toolsVersion="7525" systemVersion="14C1510" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" useTraitCollections="YES">
<document type="com.apple.InterfaceBuilder3.CocoaTouch.Storyboard.XIB" version="3.0" toolsVersion="7528.3" systemVersion="14C1514" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" useTraitCollections="YES">
<dependencies>
<plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="7516"/>
<plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="7518.3"/>
<capability name="Alignment constraints with different attributes" minToolsVersion="5.1"/>
<capability name="Aspect ratio constraints" minToolsVersion="5.1"/>
</dependencies>
+65 -1
View File
@@ -125,7 +125,13 @@
<constraint firstItem="3hF-wd-yhY" firstAttribute="top" secondItem="H20-zR-F1L" secondAttribute="top" id="zML-PE-es7"/>
</constraints>
</view>
<navigationItem key="navigationItem" title="Contacts" id="tYK-ax-VkQ"/>
<navigationItem key="navigationItem" title="Contacts" id="tYK-ax-VkQ">
<barButtonItem key="rightBarButtonItem" systemItem="search" id="JGC-Ux-Jad">
<connections>
<segue destination="Z9h-1s-JwL" kind="show" id="xjZ-jf-70R"/>
</connections>
</barButtonItem>
</navigationItem>
<connections>
<outlet property="contactsTableView" destination="3hF-wd-yhY" id="RfM-bD-4Oe"/>
</connections>
@@ -134,6 +140,64 @@
</objects>
<point key="canvasLocation" x="149" y="1045"/>
</scene>
<!--Contacts Search Table View Controller-->
<scene sceneID="eFl-rn-Dry">
<objects>
<tableViewController id="Z9h-1s-JwL" customClass="ContactsSearchTableViewController" customModule="Yep" customModuleProvider="target" sceneMemberID="viewController">
<tableView key="view" clipsSubviews="YES" contentMode="scaleToFill" alwaysBounceVertical="YES" dataMode="prototypes" style="plain" separatorStyle="default" rowHeight="44" sectionHeaderHeight="22" sectionFooterHeight="22" id="nW4-iw-wiL">
<rect key="frame" x="0.0" y="0.0" width="600" height="600"/>
<autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/>
<color key="backgroundColor" white="1" alpha="1" colorSpace="calibratedWhite"/>
<prototypes>
<tableViewCell contentMode="scaleToFill" selectionStyle="default" indentationWidth="10" reuseIdentifier="SearchUserCell" textLabel="Rex-HK-cGd" style="IBUITableViewCellStyleDefault" id="z2M-hT-Xaf">
<autoresizingMask key="autoresizingMask"/>
<tableViewCellContentView key="contentView" opaque="NO" clipsSubviews="YES" multipleTouchEnabled="YES" contentMode="center" tableViewCell="z2M-hT-Xaf" id="Fxk-Ri-ehs">
<autoresizingMask key="autoresizingMask"/>
<subviews>
<label opaque="NO" multipleTouchEnabled="YES" contentMode="left" text="" lineBreakMode="tailTruncation" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" id="Rex-HK-cGd">
<autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMaxY="YES"/>
<fontDescription key="fontDescription" type="system" pointSize="16"/>
<color key="textColor" cocoaTouchSystemColor="darkTextColor"/>
<nil key="highlightedColor"/>
</label>
</subviews>
</tableViewCellContentView>
</tableViewCell>
<tableViewCell contentMode="scaleToFill" selectionStyle="default" indentationWidth="10" id="pof-gd-kho">
<autoresizingMask key="autoresizingMask"/>
<tableViewCellContentView key="contentView" opaque="NO" clipsSubviews="YES" multipleTouchEnabled="YES" contentMode="center" tableViewCell="pof-gd-kho" id="n3r-Xn-mdD">
<autoresizingMask key="autoresizingMask"/>
</tableViewCellContentView>
</tableViewCell>
<tableViewCell contentMode="scaleToFill" selectionStyle="default" indentationWidth="10" id="2l7-0b-ght">
<autoresizingMask key="autoresizingMask"/>
<tableViewCellContentView key="contentView" opaque="NO" clipsSubviews="YES" multipleTouchEnabled="YES" contentMode="center" tableViewCell="2l7-0b-ght" id="lh4-m7-etG">
<autoresizingMask key="autoresizingMask"/>
</tableViewCellContentView>
</tableViewCell>
</prototypes>
<sections/>
<connections>
<outlet property="dataSource" destination="Z9h-1s-JwL" id="4IS-zS-lZE"/>
<outlet property="delegate" destination="Z9h-1s-JwL" id="4Oc-rT-rxk"/>
</connections>
</tableView>
<connections>
<outlet property="searchDisplayController" destination="uPO-EG-Wb8" id="TYe-Mq-FjE"/>
</connections>
</tableViewController>
<placeholder placeholderIdentifier="IBFirstResponder" id="qgo-Ya-vIo" userLabel="First Responder" sceneMemberID="firstResponder"/>
<searchDisplayController id="uPO-EG-Wb8">
<connections>
<outlet property="delegate" destination="Z9h-1s-JwL" id="Pfa-VX-YQ3"/>
<outlet property="searchContentsController" destination="Z9h-1s-JwL" id="DTr-hb-G3W"/>
<outlet property="searchResultsDataSource" destination="Z9h-1s-JwL" id="cHY-bz-mcU"/>
<outlet property="searchResultsDelegate" destination="Z9h-1s-JwL" id="pum-Kv-Wyy"/>
</connections>
</searchDisplayController>
</objects>
<point key="canvasLocation" x="149" y="1835"/>
</scene>
<!--Discover-->
<scene sceneID="n5u-x5-QaP">
<objects>
+24
View File
@@ -207,6 +207,30 @@ func loginByMobile(mobile: String, withAreaCode areaCode: String, #verifyCode: S
}
}
// MARK: Contacts
func searchUsersWithPhoneNumber(ofPhoneNumber phoneNumber: String, #failureHandler: ((Reason, String?) -> ())?, #completion: [AnyObject] -> Void) {
let requestParameters = [
"q": phoneNumber
]
let parse: JSONDictionary -> [AnyObject]? = { data in
if let users = data["users"] as? [AnyObject] {
return users
}
return []
}
let resource = authJsonResource(path: "/api/v1/users/search", method: .GET, requestParameters: requestParameters, parse: parse)
if let failureHandler = failureHandler {
apiRequest({_ in}, baseURL, resource, failureHandler, completion)
} else {
apiRequest({_ in}, baseURL, resource, defaultFailureHandler, completion)
}
}
// MARK: Upload
func publicUploadToken(#failureHandler: ((Reason, String?) -> ())?, #completion: QiniuProvider -> Void) {
@@ -0,0 +1,133 @@
//
// ContactsSearchTableViewController.swift
// Yep
//
// Created by kevinzhow on 15/3/28.
// Copyright (c) 2015 Catch Inc. All rights reserved.
//
import UIKit
class ContactsSearchTableViewController: UITableViewController,UISearchControllerDelegate,UISearchResultsUpdating {
@IBOutlet weak var contactsSearchBar: UISearchBar!
var searchController: UISearchController!
var searchResult: NSArray = []
override func viewDidLoad() {
super.viewDidLoad()
searchController = UISearchController(searchResultsController: nil)
searchController.delegate = self
searchController.searchBar.sizeToFit()
searchController.searchResultsUpdater = self
searchController.dimsBackgroundDuringPresentation = false
self.tableView.tableHeaderView = searchController.searchBar
// Uncomment the following line to preserve selection between presentations
// self.clearsSelectionOnViewWillAppear = false
// Uncomment the following line to display an Edit button in the navigation bar for this view controller.
// self.navigationItem.rightBarButtonItem = self.editButtonItem()
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
// Dispose of any resources that can be recreated.
}
// MARK: - Table view data source
override func numberOfSectionsInTableView(tableView: UITableView) -> Int {
// #warning Potentially incomplete method implementation.
// Return the number of sections.
return 1
}
override func tableView(tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
// #warning Incomplete method implementation.
// Return the number of rows in the section.
return searchResult.count
}
override func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {
let cell = tableView.dequeueReusableCellWithIdentifier("SearchUserCell", forIndexPath: indexPath) as! UITableViewCell
let user = searchResult.objectAtIndex(indexPath.row) as! NSDictionary
cell.textLabel?.text = user.valueForKey("nickname") as? String
return cell
}
func updateSearchResultsForSearchController(searchController: UISearchController) {
//do whatever with searchController here.
var searchText = searchController.searchBar.text
println(searchText)
searchUsersWithPhoneNumber(ofPhoneNumber: searchText, failureHandler: { (reason, errorMessage) in
}, completion: { users in
self.searchResult = users
if (self.searchResult.count > 0) {
dispatch_async(dispatch_get_main_queue()) {
self.tableView.reloadData()
}
}
}
)
}
override func tableView(tableView: UITableView, didSelectRowAtIndexPath indexPath: NSIndexPath) {
let user = searchResult.objectAtIndex(indexPath.row) as! NSDictionary
}
/*
// Override to support conditional editing of the table view.
override func tableView(tableView: UITableView, canEditRowAtIndexPath indexPath: NSIndexPath) -> Bool {
// Return NO if you do not want the specified item to be editable.
return true
}
*/
/*
// Override to support editing the table view.
override func tableView(tableView: UITableView, commitEditingStyle editingStyle: UITableViewCellEditingStyle, forRowAtIndexPath indexPath: NSIndexPath) {
if editingStyle == .Delete {
// Delete the row from the data source
tableView.deleteRowsAtIndexPaths([indexPath], withRowAnimation: .Fade)
} else if editingStyle == .Insert {
// Create a new instance of the appropriate class, insert it into the array, and add a new row to the table view
}
}
*/
/*
// Override to support rearranging the table view.
override func tableView(tableView: UITableView, moveRowAtIndexPath fromIndexPath: NSIndexPath, toIndexPath: NSIndexPath) {
}
*/
/*
// Override to support conditional rearranging of the table view.
override func tableView(tableView: UITableView, canMoveRowAtIndexPath indexPath: NSIndexPath) -> Bool {
// Return NO if you do not want the item to be re-orderable.
return true
}
*/
/*
// MARK: - Navigation
// In a storyboard-based application, you will often want to do a little preparation before navigation
override func prepareForSegue(segue: UIStoryboardSegue, sender: AnyObject?) {
// Get the new view controller using [segue destinationViewController].
// Pass the selected object to the new view controller.
}
*/
}