adding a custom view to a alert view

Darshana picture Darshana · Apr 25, 2014 · Viewed 17.6k times · Source

i have a problem like this:

i want to show a customized view inside a alert view. so i create a separate xib file and designed my interface.and implemented the class for it too.but when i apply below code,it gives me an error.

this is the code :

 UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Confirm your Action"
                                                    message:@"Click OK to confirm"
                                                   delegate:self
                                          cancelButtonTitle:@"OK"
                                          otherButtonTitles:@"Cancel",nil];


    NSArray *subviewArray = [[NSBundle mainBundle] loadNibNamed:@"customDialogViewController"  owner:self options:nil];
    customDialogViewController *myView = (customDialogViewController*) [subviewArray objectAtIndex:0];

    [alert setValue:myView forKey:@"accessoryView"];
    //alert.alertViewStyle = UIAlertViewStylePlainTextInput;
    alert.tag = KAlertViewthree;
    [alert show];

and this is my error :

Terminating app due to uncaught exception 'UIViewControllerHierarchyInconsistency', reason: 'child view controller:<ScheduleView: 0x8adf1a0> should have parent view controller:<_UIModalItemAccessoryViewControllerForLegacyAlert: 0xa888b70> but actual parent is:<UINavigationController: 0x8add8c0>'

i really new to iOS development.did i do this wrong ? where is the mistake ? i don't know what is this Nib file talking here "loadNibNamed:@bla boa " i just gave my xib name for that. can anyone give me a better way to do this or can you tell me the where i have to change to fix this issue ?

please guide me some one.. thank you.

Answer

पवन picture पवन · Apr 25, 2014