Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Compiled with Xcode 7.1.1 and show the drop down on top of other views #25

Open
wants to merge 6 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
MPGTextField
=========

Modified this project for this question: [Swift MPGTextField autocomplete in tableview cell](http://stackoverflow.com/q/33692207/1378447)

<p align="center"><img src = "https://dl.dropboxusercontent.com/u/90817764/MPGTextField.png" width=320 height = 568 align="center"></p>

An autocomplete textfield for iOS which provides suggestions as you type. The textfield can be configured to ensure that a selection is compulsorily made from the list of suggestions and gives you control over the size of the popover showing suggestions based on the text entered by the user.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,8 @@
0ACD2D491944D84D005AF774 /* Project object */ = {
isa = PBXProject;
attributes = {
LastSwiftMigration = 0710;
LastSwiftUpdateCheck = 0710;
LastUpgradeCheck = 0600;
ORGANIZATIONNAME = Mappgic;
TargetAttributes = {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,8 @@ class AppDelegate: UIResponder, UIApplicationDelegate {

var window: UIWindow?


func application(application: UIApplication, didFinishLaunchingWithOptions launchOptions: NSDictionary?) -> Bool {
func applicationDidFinishLaunching(application: UIApplication) {
// Override point for customization after application launch.
return true
}

func applicationWillResignActive(application: UIApplication) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<document type="com.apple.InterfaceBuilder3.CocoaTouch.Storyboard.XIB" version="3.0" toolsVersion="6154.17" systemVersion="13D65" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" useTraitCollections="YES" initialViewController="vXZ-lx-hvc">
<document type="com.apple.InterfaceBuilder3.CocoaTouch.Storyboard.XIB" version="3.0" toolsVersion="9060" systemVersion="14F27" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" useTraitCollections="YES" initialViewController="vXZ-lx-hvc">
<dependencies>
<plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="6153.11"/>
<deployment identifier="iOS"/>
<plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="9051"/>
</dependencies>
<scenes>
<!--View Controller-->
Expand All @@ -13,7 +14,7 @@
<viewControllerLayoutGuide type="bottom" id="2fi-mo-0CV"/>
</layoutGuides>
<view key="view" contentMode="scaleToFill" id="kh9-bI-dsS">
<rect key="frame" x="0.0" y="0.0" width="480" height="480"/>
<rect key="frame" x="0.0" y="0.0" width="600" height="600"/>
<autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMaxY="YES"/>
<subviews>
<textField opaque="NO" clipsSubviews="YES" contentMode="scaleToFill" fixedFrame="YES" contentHorizontalAlignment="left" contentVerticalAlignment="center" placeholder="Name" minimumFontSize="17" translatesAutoresizingMaskIntoConstraints="NO" id="kwb-U6-pNw" customClass="MPGTextField_Swift" customModule="MPGTextField_Swift" customModuleProvider="target">
Expand All @@ -36,6 +37,31 @@
<rect key="frame" x="20" y="148" width="280" height="30"/>
</variation>
</textField>
<tableView clipsSubviews="YES" contentMode="scaleToFill" fixedFrame="YES" alwaysBounceVertical="YES" dataMode="prototypes" style="plain" separatorStyle="default" rowHeight="44" sectionHeaderHeight="28" sectionFooterHeight="28" translatesAutoresizingMaskIntoConstraints="NO" id="Tgv-Ji-qyO">
<rect key="frame" x="59" y="177" width="298" height="156"/>
<color key="backgroundColor" white="1" alpha="1" colorSpace="calibratedWhite"/>
<prototypes>
<tableViewCell clipsSubviews="YES" contentMode="scaleToFill" selectionStyle="blue" hidesAccessoryWhenEditing="NO" indentationLevel="1" indentationWidth="0.0" reuseIdentifier="cell" id="9Ui-ri-RD5">
<rect key="frame" x="0.0" y="28" width="298" height="44"/>
<autoresizingMask key="autoresizingMask"/>
<tableViewCellContentView key="contentView" opaque="NO" clipsSubviews="YES" multipleTouchEnabled="YES" contentMode="center" tableViewCell="9Ui-ri-RD5" id="mEQ-dM-oNW">
<rect key="frame" x="0.0" y="0.0" width="298" height="43"/>
<autoresizingMask key="autoresizingMask"/>
<subviews>
<textField opaque="NO" clipsSubviews="YES" tag="420" contentMode="scaleToFill" fixedFrame="YES" contentHorizontalAlignment="left" contentVerticalAlignment="center" borderStyle="roundedRect" textAlignment="natural" minimumFontSize="17" translatesAutoresizingMaskIntoConstraints="NO" id="JjJ-NB-hXb" customClass="MPGTextField_Swift" customModule="MPGTextField_Swift" customModuleProvider="target">
<rect key="frame" x="100" y="7" width="97" height="30"/>
<fontDescription key="fontDescription" type="system" pointSize="14"/>
<textInputTraits key="textInputTraits"/>
</textField>
</subviews>
</tableViewCellContentView>
</tableViewCell>
</prototypes>
<connections>
<outlet property="dataSource" destination="vXZ-lx-hvc" id="liE-Hi-OQm"/>
<outlet property="delegate" destination="vXZ-lx-hvc" id="9Tr-f7-5qz"/>
</connections>
</tableView>
<label opaque="NO" clipsSubviews="YES" userInteractionEnabled="NO" contentMode="left" horizontalHuggingPriority="251" verticalHuggingPriority="251" text="Swift" lineBreakMode="tailTruncation" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" translatesAutoresizingMaskIntoConstraints="NO" id="StC-uo-gDe">
<rect key="frame" x="0.0" y="-21" width="42" height="21"/>
<fontDescription key="fontDescription" name="HelveticaNeue-Light" family="Helvetica Neue" pointSize="30"/>
Expand Down Expand Up @@ -97,7 +123,6 @@
</label>
</subviews>
<color key="backgroundColor" white="1" alpha="1" colorSpace="custom" customColorSpace="calibratedWhite"/>
<simulatedOrientationMetrics key="simulatedOrientationMetrics" orientation="landscapeRight"/>
<variation key="default">
<mask key="subviews">
<exclude reference="StC-uo-gDe"/>
Expand All @@ -123,7 +148,7 @@
</viewController>
<placeholder placeholderIdentifier="IBFirstResponder" id="x5A-6p-PRh" sceneMemberID="firstResponder"/>
</objects>
<point key="canvasLocation" x="430.5" y="406.5"/>
<point key="canvasLocation" x="430" y="406"/>
</scene>
</scenes>
</document>
41 changes: 28 additions & 13 deletions Swift/MPGTextField-Swift/MPGTextField-Swift/ViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,14 @@ import UIKit

class ViewController: UIViewController, MPGTextFieldDelegate {

var sampleData = Dictionary<String, AnyObject>[]()
@IBOutlet var name : MPGTextField_Swift
var sampleData = [Dictionary<String, AnyObject>]()
@IBOutlet var name : MPGTextField_Swift?

override func viewDidLoad() {
super.viewDidLoad()
// Do any additional setup after loading the view, typically from a nib.
self.generateData()
name.mDelegate = self
name!.mDelegate = self
}

override func didReceiveMemoryWarning() {
Expand All @@ -26,24 +26,24 @@ class ViewController: UIViewController, MPGTextFieldDelegate {
}

func generateData(){
var err : NSErrorPointer?
var dataPath = NSBundle.mainBundle().pathForResource("sample_data", ofType: "json")
var data = NSData.dataWithContentsOfFile(dataPath, options: NSDataReadingOptions.DataReadingUncached, error: err!)
var contents : AnyObject[]! = NSJSONSerialization.JSONObjectWithData(data, options: NSJSONReadingOptions.AllowFragments, error: err!) as AnyObject[]
//var err : NSErrorPointer?
let dataPath = NSBundle.mainBundle().pathForResource("sample_data", ofType: "json")
let data = try? NSData(contentsOfFile: dataPath!, options: .DataReadingUncached)
var contents : [AnyObject]! = try? NSJSONSerialization.JSONObjectWithData(data!, options: NSJSONReadingOptions.AllowFragments) as! [AnyObject]
//println(contents[0]["first_name"])
for var i = 0;i<contents.count;++i{
var name = contents[i]["first_name"] as String
var lName = contents[i]["last_name"] as String
var name = contents[i]["first_name"] as! String
let lName = contents[i]["last_name"] as! String
name += " " + lName
var email = contents[i]["email"] as String
var dictionary = ["DisplayText":name,"DisplaySubText":email,"CustomObject":contents[i]]
let email = contents[i]["email"] as! String
let dictionary = ["DisplayText":name,"DisplaySubText":email,"CustomObject":contents[i]]

sampleData.append(dictionary)
}

}

func dataForPopoverInTextField(textfield: MPGTextField_Swift) -> Dictionary<String, AnyObject>[]
func dataForPopoverInTextField(textfield: MPGTextField_Swift) -> [Dictionary<String, AnyObject>]
{
return sampleData
}
Expand All @@ -53,7 +53,22 @@ class ViewController: UIViewController, MPGTextFieldDelegate {
}

func textFieldDidEndEditing(textField: MPGTextField_Swift, withSelection data: Dictionary<String,AnyObject>){
println("Dictionary received = \(data)")
print("Dictionary received = \(data)")
}
}

extension ViewController : UITableViewDataSource {

func tableView(tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
return 10;
}

func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {
let cell = tableView.dequeueReusableCellWithIdentifier("cell", forIndexPath: indexPath)
let mpgTextField = cell.viewWithTag(420) as! MPGTextField_Swift
mpgTextField.mDelegate = self;

return cell
}
}

Loading