ios - Show UIAlertController from a common utility class -


i working on project uses uialertview, problem have replace of uialertview's uialertcontroller's , there around 1250 of them in code. planning uses existing utility class create function this, following planning do:

+(void)showalert:(nsstring *)title errormessage:(nsstring *)msg {     uialertcontroller *alertcontroller = [uialertcontroller      alertcontrollerwithtitle:title message:msg preferredstyle:uialertcontrollerstylealert];     [alertcontroller addaction:[uialertaction actionwithtitle:@"ok" style:uialertactionstyledefault handler:nil]];     [self presentviewcontroller:alertcontroller animated:yes completion:nil]; } 

i have following questions before doing this: 1 - worth efforts (using uialertcontroller instead of uialertview) ? 2 - how handle uialertview's had tags , different delegate implementation across hundreds of files ? 3 - fourth line function above gives error : no known class method selector 'presentviewcontroller:animated:completion:'

any appreciated.

you've use uialertcontroller uialertview deprecated.

apple doc says:

in apps run in versions of ios prior ios 8, use uialertview class display alert message user. alert view functions similar differs in appearance action sheet (an instance of uiactionsheet). uialertview deprecated in ios 8. (note uialertviewdelegate deprecated.) create , manage alerts in ios 8 , later, instead use uialertcontroller preferredstyle of uialertcontrollerstylealert. availability

alternatively, can way. in utils class, this:

+ (void)showalertwithtitle:(nsstring *)title message:(nsstring *)msg controller:(id)controller {     uialertcontroller *alertcontroller = [uialertcontroller alertcontrollerwithtitle:title message:msg preferredstyle:uialertcontrollerstylealert];      uialertaction *okaction = [uialertaction actionwithtitle:@"ok" style:uialertactionstyledefault handler:nil];      [alertcontroller addaction:okaction];      [controller presentviewcontroller:alertcontroller animated:yes completion:nil]; } 

usage viewcontroller class:

[utils showalertwithtitle:@"camera" message:@"it seems device doesn't support camera. " controller: self]; 

if existing uialertview having tags you've use uialertviewcontroller class instead of util method.

hope helps.


Comments

Popular posts from this blog

angular - Ionic slides - dynamically add slides before and after -

minify - Minimizing css files -

Add a dynamic header in angular 2 http provider -