Add UIViewController on alertView

4 posts, 0 answers
  1. yahya
    yahya avatar
    3 posts
    Member since:
    Mar 2016

    Posted 10 Apr Link to this post

    I need to add UIViewController i created it To AlertView,

    i added that and set bounds in alert view and all right, but when i click in button on viewcontroller anything wasn't happend!!

    i need to interactive with viewcontroller from alertview

    Can i do this? Thank You.

  2. Sophi
    Admin
    Sophi avatar
    99 posts

    Posted 14 Apr Link to this post

    Hello Yahya,

    I tried reproducing your case but I am not sure that I am using the proper setup in order to reproduce the described behavior.
    Could you, please, send us a sample project with the isolated problem so that we can provide you with solution in short terms.
    Thank you for your understanding.
    Looking forward to hearing from you.

    Regards,
    Sophi
    Telerik
    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Feedback Portal and vote to affect the priority of the items
  3. DevCraft banner
  4. yahya
    yahya avatar
    3 posts
    Member since:
    Mar 2016

    Posted 24 Apr in reply to Sophi Link to this post

    Thank You very much For Reply.

    I would simply like to add a viewController To alertView by Telerik,

    like this in swift:

    let alert = TKAlert()
    alert.delegate = self
    let vc = storyboard?.instantiateViewControllerWithIdentifier("ViewController2") as! ViewController2
    vc.view.frame = alert.alertView.bounds
    alert.alertView.addSubview(vc.view)
    alert.show(true)

     

    The ViewController1 show a viewController2 in AlertView Very Well,

    but when i click on any button on that(viewController2) anything wasn't execute :\

  5. Sophi
    Admin
    Sophi avatar
    99 posts

    Posted 28 Apr Link to this post

    Hello Yahya,

    You should try handling the tap and interaction events in your host ViewController. I guess that you are handling the tap events inside the viewController2, you should have in mind that the host ViewController1 is getting all the touch events and nothing gets to be executed inside the ViewController2.
    Consider the following snippet. I have created a second viewController with a button and a label, which is child of the TKAlert. Then I have provided a .touchUpInside handler in my base controller.
    import UIKit
     
    class ViewController: UIViewController {
         
        let lbl = UILabel()
     
        override func viewDidLoad() {
            super.viewDidLoad()
             
           let showbtn = UIButton(frame: CGRect(x: 60, y: 100, width: 100, height: 30))
            showbtn.backgroundColor = UIColor.purpleColor()
            showbtn.setTitle("Show", forState: UIControlState.Normal)
            showbtn.addTarget(self, action: #selector(ViewController.open), forControlEvents: UIControlEvents.TouchUpInside)
            self.view.addSubview(showbtn)
        }
         
        func open() {
            let alert = TKAlert()
            alert.dismissMode = TKAlertDismissMode.Tap
             
            let ctrl = UIViewController()
            ctrl.view.backgroundColor = UIColor.purpleColor()
            ctrl.view.frame = alert.alertView.bounds
             
            lbl.frame = CGRect(x: 10, y: 40, width: 150, height: 30)
            ctrl.view.addSubview(lbl)
             
            let btn = UIButton()
            btn.frame = CGRect(x: 10, y: 10, width: 150, height: 30)
            btn.backgroundColor = UIColor.blueColor()
            btn.setTitle("Show text", forState: UIControlState.Normal)
            btn.addTarget(self, action: #selector(ViewController.click), forControlEvents: UIControlEvents.TouchUpInside)
            ctrl.view.addSubview(btn)
     
            alert.alertView.addSubview(ctrl.view)
             
            alert.show(true)
        }
         
        func click(){
            lbl.text = "Button was clicked";
        }
     
    }


    Regards,
    Sophi
    Telerik
    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Feedback Portal and vote to affect the priority of the items
Back to Top
DevCraft banner