objective c - AlertView issue in iOS 8 -


i added uiview in alertview follow:

uiview *alertsubview = [[uiview alloc]initwithframe:cgrectmake(0, 0, 260, 55)];         [alertsubview addsubview:textfield];         [alertsubview addsubview:charleftlabel];          [alert setvalue:alertsubview forkey:@"accessoryview"]; 

problem

uiview* alertsubview = [alertview valueforkey:@"accessoryview"]; 

app crash when try subview in alertview delegate method.

it working fine in ios7 there issue ios 8 only

error terminating app due uncaught exception 'nsunknownkeyexception', reason: '[ valueforundefinedkey:]: class not key value coding-compliant key accessoryview.

alert view deprecated. should use uialertcontroller. suggestion.

for example aspect :

uialertcontroller *alertcontroller = [uialertcontroller                                       alertcontrollerwithtitle:@"alert controller"                                       message:@"alert message"                                       preferredstyle:uialertcontrollerstylealert];  uiviewcontroller *viewcontroller = [[uiviewcontroller alloc]init]; [viewcontroller.view setbackgroundcolor:[uicolor bluecolor]];  uilabel *lbl = [[uilabel alloc]initwithframe:cgrectmake(10, 8, 250, 30)]; lbl.text = @"this label"; lbl.textalignment = nstextalignmentcenter; lbl.textcolor = [uicolor whitecolor]; [viewcontroller.view addsubview:lbl];  uitextfield *tf = [[uitextfield alloc]initwithframe:cgrectmake(10, 35, 250, 30)]; tf.borderstyle = uitextborderstyleroundedrect; tf.placeholder = @"enter name"; [viewcontroller.view addsubview:tf];  [alertcontroller setvalue:viewcontroller forkey:@"contentviewcontroller"];  uialertaction *cancelaction = [uialertaction                                actionwithtitle:@"cancel"                                style:uialertactionstylecancel                                handler:^(uialertaction *action)                                {                                    nslog(@"cancel action");                                }];  uialertaction *okaction = [uialertaction                            actionwithtitle:@"ok"                            style:uialertactionstyledefault                            handler:^(uialertaction *action)                            {                                nslog(@"ok action");                                 nslog(@"text value : %@",tf.text);                            }];  [alertcontroller addaction:cancelaction]; [alertcontroller addaction:okaction];  dispatch_async(dispatch_get_main_queue(), ^{     [self presentviewcontroller:alertcontroller animated:yes completion:nil]; }); 

enter image description here

hope helps you.


Comments

Popular posts from this blog

java - Date formats difference between yyyy-MM-dd'T'HH:mm:ss and yyyy-MM-dd'T'HH:mm:ssXXX -

c# - Get rid of xmlns attribute when adding node to existing xml -