Skip to content
Open
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
45 changes: 18 additions & 27 deletions UIDropDown/UIDropDown.swift
Original file line number Diff line number Diff line change
Expand Up @@ -160,16 +160,6 @@ public class UIDropDown: UIControl {
self.layer.borderWidth = borderWidth
self.layer.borderColor = borderColor.cgColor
self.addTarget(self, action: #selector(touch), for: .touchUpInside)
}

@objc fileprivate func touch() {
isSelected = !isSelected
isSelected ? showTable() : hideTable()
}

fileprivate func showTable() {

privateTableWillAppear()

table = UITableView(frame: CGRect(x: self.frame.minX,
y: self.frame.minY,
Expand All @@ -182,7 +172,21 @@ public class UIDropDown: UIControl {
table.layer.borderWidth = optionsBorderWidth
table.layer.borderColor = optionsBorderColor.cgColor
table.rowHeight = rowHeight ?? table.rowHeight
self.superview?.insertSubview(table, belowSubview: self)
}

@objc fileprivate func touch() {
isSelected = !isSelected
isSelected ? showTable() : hideTable()
}

fileprivate func showTable() {

privateTableWillAppear()

self.table.isHidden = false
if (self.table.superview) == nil {
self.superview?.insertSubview(table, belowSubview: self)
}

switch animationType {
case .Default:
Expand Down Expand Up @@ -271,7 +275,7 @@ public class UIDropDown: UIControl {
self.arrow.position = .down
},
completion: { (didFinish) -> Void in
self.table.removeFromSuperview()
self.table.isHidden = true
self.isSelected = false
self.privateTableDidDisappear()
})
Expand All @@ -292,7 +296,7 @@ public class UIDropDown: UIControl {
self.arrow.position = .down
},
completion: { (didFinish) -> Void in
self.table.removeFromSuperview()
self.table.isHidden = true
self.isSelected = false
self.privateTableDidDisappear()
})
Expand Down Expand Up @@ -354,24 +358,11 @@ extension UIDropDown: UITableViewDataSource {

extension UIDropDown: UITableViewDelegate {
public func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {

selectedIndex = (indexPath as NSIndexPath).row

title.alpha = 0.0
title.text = "\(self.options[(indexPath as NSIndexPath).row])"

UIView.animate(withDuration: 0.6,
animations: { () -> Void in
self.title.alpha = 1.0
})

tableView.reloadData()

if hideOptionsWhenSelect {
hideTable()
}

privatedidSelect("\(self.options[indexPath.row])", selectedIndex!)
privatedidSelect("\(self.options[indexPath.row])", indexPath.row)
}
}

Expand Down