Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- var steppers : UIStepper?
- @IBOutlet weak var hourLabel: UILabel!
- @IBAction func stepper(_ sender: UIStepper) {
- hourLabel.text = String(sender.value)
- }
- import UIKit
- import AVFoundation
- class SelectClass: UIViewController, UITableViewDelegate, UITableViewDataSource {
- @IBOutlet weak var tableView: UITableView!
- var list : [QCategoryy] = [QCategoryy]()
- var audioPlayer : AVAudioPlayer!
- var limit = 3
- override func viewDidLoad() {
- super.viewDidLoad()
- tableView.delegate = self
- tableView.dataSource = self
- tableView.allowsMultipleSelection = true
- self.title = "Categories"
- list = NearbyPlaces.getCategories()
- }
- override func viewWillAppear(_ animated: Bool) {
- super.viewWillAppear(animated)
- list.sort() { $0.views > $1.views}
- tableView.reloadData()
- }
- override func didReceiveMemoryWarning() {
- super.didReceiveMemoryWarning()
- // Dispose of any resources that can be recreated.
- }
- @IBAction func backTapp(_ sender: Any) {
- let audioUrl = NSURL.fileURL(withPath: Bundle.main.path(forResource: "pop_drip", ofType: "m4a")!)
- do{
- try AVAudioSession.sharedInstance().setActive(true)
- try AVAudioSession.sharedInstance().setCategory(AVAudioSessionCategoryPlayback)
- try audioPlayer = AVAudioPlayer(contentsOf: audioUrl)
- audioPlayer.prepareToPlay()
- audioPlayer.play()
- }
- catch _ as NSError
- {
- }
- dismiss(animated: true, completion: nil)
- }
- @IBAction func doneTapp(_ sender: Any) {
- let audioUrl = NSURL.fileURL(withPath: Bundle.main.path(forResource: "pop_drip", ofType: "m4a")!)
- do{
- try AVAudioSession.sharedInstance().setActive(true)
- try AVAudioSession.sharedInstance().setCategory(AVAudioSessionCategoryPlayback)
- try audioPlayer = AVAudioPlayer(contentsOf: audioUrl)
- audioPlayer.prepareToPlay()
- audioPlayer.play()
- }
- catch _ as NSError
- {
- }
- self.performSegue(withIdentifier: nearbySearchSegueIdentifier, sender: nil)
- }
- func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
- return list.count
- }
- func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
- let identifier = "CATEGORY_CELL"
- let cell = tableView.dequeueReusableCell(withIdentifier: identifier, for: indexPath)
- let selectedIndexPaths = tableView.indexPathsForSelectedRows
- let rowIsSelected = selectedIndexPaths != nil && selectedIndexPaths!.contains(indexPath)
- /* cell.accessoryType = rowIsSelected ? .checkmark : .none */
- cell.accessoryType = list[indexPath.row].isSelected ? .checkmark : .none
- cell.textLabel?.text = list[indexPath.row].name
- return cell
- }
- let nearbySearchSegueIdentifier = "goToMcourse"
- func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
- let cell = tableView.cellForRow(at: indexPath)!
- cell.accessoryType = .checkmark
- /* self.performSegue(withIdentifier: nearbySearchSegueIdentifier, sender: list[indexPath.row]) */
- }
- func tableView(_ tableView: UITableView, didDeselectRowAt indexPath: IndexPath) {
- let cell = tableView.cellForRow(at: indexPath)!
- cell.accessoryType = .none
- }
- func tableView(_ tableView: UITableView, willSelectRowAt indexPath: IndexPath) -> IndexPath? {
- if let sr = tableView.indexPathsForSelectedRows {
- if sr.count == limit {
- let alertController = UIAlertController(title: "Oops", message:
- "You are limited to (limit) selections", preferredStyle: .alert)
- alertController.addAction(UIAlertAction(title: "OK", style: .default, handler: {action in
- }))
- self.present(alertController, animated: true, completion: nil)
- return nil
- }
- }
- return indexPath
- }
- override func prepare(for segue: UIStoryboardSegue, sender: Any?) {
- if segue.identifier == nearbySearchSegueIdentifier {
- guard let category = sender as? QCategoryy else {
- return
- }
- if let selectedRows = tableView.indexPathsForSelectedRows {
- if let vc = segue.destination as? CourseClass2 {
- vc.category = category
- }
- }
- }
- }
- }
- extension QCategoryy {
- private static let ketPrefix = "category-"
- var views:Int {
- get {
- return UserDefaults.standard.integer(forKey: QCategoryy.ketPrefix + name)
- }
- }
- func markView() {
- UserDefaults.standard.set(views + 1, forKey: QCategoryy.ketPrefix + name)
- }
- }
- var limit = 3
- func tableView(_ tableView: UITableView, willSelectRowAt indexPath: IndexPath) -> IndexPath? {
- if let sr = tableView.indexPathsForSelectedRows {
- if sr.count == limit {
- let alertController = UIAlertController(title: "Oops", message:
- "You are limited to (limit) selections", preferredStyle: .alert)
- alertController.addAction(UIAlertAction(title: "OK", style: .default, handler: {action in
- }))
- self.present(alertController, animated: true, completion: nil)
- return nil
- }
- }
- return indexPath
- }
Add Comment
Please, Sign In to add comment