This is a migrated thread and some comments may be shown as answers.

Add UIViewController on alertView

3 Answers 158 Views
Alert
This is a migrated thread and some comments may be shown as answers.
This question is locked. New answers and comments are not allowed.
yahya
Top achievements
Rank 1
yahya asked on 10 Apr 2016, 11:51 AM

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.

3 Answers, 1 is accepted

Sort by
0
Sophi
Telerik team
answered on 14 Apr 2016, 07:05 AM
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
0
yahya
Top achievements
Rank 1
answered on 24 Apr 2016, 08:09 PM

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 :\

0
Sophi
Telerik team
answered on 28 Apr 2016, 08:05 AM
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
Tags
Alert
Asked by
yahya
Top achievements
Rank 1
Answers by
Sophi
Telerik team
yahya
Top achievements
Rank 1
Share this question
or