Code Monkey home page Code Monkey logo

customalertviewcontroller's Introduction

CustomAlertViewController

CustomAlertViewController.swift is custom class which do all work of showing custom alert controller.

This can be called like

/* Item index defined using enum */

enum ItemIndex { case ProfileIndex case CallIndex }

/* Utility method for creating item dictionary */

func getItemDictionary(title: String, index: ItemIndex) -> NSMutableDictionary {

    let dictionary = NSMutableDictionary()
    dictionary.setObject(title, forKey: "title" as NSCopying)
    dictionary.setObject(index, forKey: "index" as NSCopying)
    
    return dictionary
}

@IBAction func alertButtonSelected(_ sender: Any) { let actionArray: NSMutableArray = NSMutableArray()

    var itemDictionary  = getItemDictionary(title: "Show Profile", index: ItemIndex.ProfileIndex)
    actionArray.add(itemDictionary)
    
    itemDictionary  = getItemDictionary(title: "Call", index: ItemIndex.CallIndex)
    actionArray.add(itemDictionary)
    
    let alertController:CustomAlertViewController = CustomAlertViewController(headerImage: UIImage(named: "userProfile")!,
                                                                              headerTitle: "Edmond Halley",
                                                                              headerSubText: "Tech Lead",
                                                                              actionArray: actionArray) as CustomAlertViewController
    alertController.delegate = self
    
    let defaultAction = UIAlertAction(title: "OK", style: .default, handler: nil)
    alertController.addAction(defaultAction)
    
    present(alertController, animated: true, completion: nil)
}

/* This is callback method from CustomAlertViewController about item selection */

func OptionSelected(itemDictionary: NSMutableDictionary) {
    
    let index = itemDictionary.object(forKey: "index") as! ItemIndex
    
    switch index {
    case .ProfileIndex:
        print("Profile option selected")
    case .CallIndex:
        print("Call option selected")
    }
}

customalertviewcontroller's People

Contributors

sagarmane19 avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.