Skip to content

Commit

Permalink
Adds showCallingCodes flag and documentation
Browse files Browse the repository at this point in the history
  • Loading branch information
phowat committed Jun 24, 2016
1 parent bec35de commit 770254d
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 6 deletions.
5 changes: 4 additions & 1 deletion MICountryPicker/ViewController.swift
Expand Up @@ -32,7 +32,10 @@ class ViewController: UIViewController {

// delegate
picker.delegate = self


// Display calling codes
// picker.showCallingCodes = true

// or closure
picker.didSelectCountryClosure = { name, code in
picker.navigationController?.popToRootViewControllerAnimated(true)
Expand Down
14 changes: 12 additions & 2 deletions README.md
Expand Up @@ -4,13 +4,13 @@ MICountryPicker is a country picker controller for iOS8+ with an option to searc

## Screenshots

![alt tag](https://github.com/mustafaibrahim989/MICountryPicker/blob/master/screen1.png) ![alt tag](https://github.com/mustafaibrahim989/MICountryPicker/blob/master/screen2.png)
![alt tag](https://github.com/mustafaibrahim989/MICountryPicker/blob/master/screen1.png) ![alt tag](https://github.com/mustafaibrahim989/MICountryPicker/blob/master/screen2.png) ![alt tag](https://github.com/mustafaibrahim989/MICountryPicker/blob/master/screen3.png)

## Installation

MICountryPicker is available through [CocoaPods](http://cocoapods.org), to install
it simply add the following line to your Podfile:

use_frameworks!
pod 'MICountryPicker'

Expand All @@ -29,6 +29,9 @@ navigationController?.pushViewController(picker, animated: true)
// delegate
picker.delegate = self

// Optionally, set this to display the country calling codes after the names
picker.showCallingCodes = true

```

```swift
Expand All @@ -37,6 +40,9 @@ func countryPicker(picker: MICountryPicker, didSelectCountryWithName name: Strin
print(code)
}

func countryPicker(picker: MICountryPicker, didSelectCountryWithName name: String, code: String, dialCode: String) {
print(dialCode)
}
```

## Closure
Expand All @@ -48,6 +54,10 @@ picker.didSelectCountryClosure = { name, code in
print(code)
}

picker.didSelectCountryWithCallingCodeClosure = { name, code, dialCode in
print(dialCode)
}

```

## Author
Expand Down
10 changes: 7 additions & 3 deletions Source/MICountryPicker.swift
Expand Up @@ -1263,13 +1263,11 @@ public class MICountryPicker: UITableViewController {
let countryData = CallingCodes.filter { $0["code"] == countryCode }
let country: MICountry

print(countryData)
if countryData.count > 0, let dialCode = countryData[0]["dial_code"] {
country = MICountry(name: displayName!, code: countryCode, dialCode: dialCode)
} else {
country = MICountry(name: displayName!, code: countryCode)
}
print(country)
unsourtedCountries.append(country)
}

Expand Down Expand Up @@ -1315,6 +1313,7 @@ public class MICountryPicker: UITableViewController {
public weak var delegate: MICountryPickerDelegate?
public var didSelectCountryClosure: ((String, String) -> ())?
public var didSelectCountryWithCallingCodeClosure: ((String, String, String) -> ())?
public var showCallingCodes = false

convenience public init(completionHandler: ((String, String) -> ())) {
self.init()
Expand Down Expand Up @@ -1394,7 +1393,12 @@ extension MICountryPicker {

}

cell.textLabel?.text = country.name + " (" + country.dialCode! + ")"
if showCallingCodes {
cell.textLabel?.text = country.name + " (" + country.dialCode! + ")"
} else {
cell.textLabel?.text = country.name
}

let bundle = "assets.bundle/"
cell.imageView!.image = UIImage(named: bundle + country.code.lowercaseString + ".png", inBundle: NSBundle(forClass: MICountryPicker.self), compatibleWithTraitCollection: nil)
return cell
Expand Down
Binary file added screen3.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit 770254d

Please sign in to comment.