Adding View Controller's view to UIAlertView (Objective c)

I have ViewController with UITableView. if i touch on any Cell, it shows information about this Cell in another view. It is working well. But when i add MyViewController's view to UIAlerView's view, if i touch on AlertView, it is giving runtime error. this is my code:

UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Title" message:@"" delegate:self cancelButtonTitle:@"OK" otherButtonTitles: nil];
MyViewController *VC = [[MyViewController alloc] init];
[alert setValue:VC.view forKey:@"accessoryView"];
[alert show];

any help please ... my program shows like this:


An alert view is simply shown on the screen. It doesn't matter which view controller is currently visible, when the show method is called, the alert view is added as the top view.

The only thing that would matter in terms of view controllers is which one you want as the delegate view controller, which can be assigned to objects other than self.

Refactor your code to look like this:

MyViewController *VC = [[MyViewController alloc] init];
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Title" message:@"" delegate:VC cancelButtonTitle:@"OK" otherButtonTitles: nil];
[alert show];

Notice how the VC you want to display is now the delegate to the alert?

Need Your Help

drag and drop cell from datagridview to another

c# datagridview drag-and-drop

I have 2 datagridviews and i want to copy cells from the datagridview1 to datagridview2 (a cell at a time).I´m able to select the cell I want and drag it to the datagridview2 but the value is not s...

AdoNetAppender stops working after changes are made

c# .net log4net adonetappender

I'm using log4net and I configured my XML file to log into database with AdoNetAppender and everything seems to work properly when I create the application and configure everything. And I can