iphone - AlertView defined outside ViewController -


for easier code reading decided create alertview new object. created class alertviews subclass of nsobject. created 2 uialertview - 1 single text field , other plain uialertview. test it, wanted input text in uialertview click ok , see nslog.

alertviews.h

@interface alertviews: nsobject  {     uialertview *addsomethingalertview;    uialertview * showsomethingav;  }   @property (nonatomic, retain) uialertview *addsomethingalertview; @property (nonatomic, retain) uialertview *showsomethingav;  -(void)initializeaddsomethingalertview; -(void)initializeshowsomethingav; 

alertviews.m

@implementation   @synthesize addsomethingalertview = _addsomethingalertview; @synthesize showsomethingav = _showsomethingav;  -(void)initializeaddsomethingalertview {      addsomethingalertview = [[uialertview alloc] initwithtitle:@"something"      message:@"something" delegate:self cancelbuttontitle:@"cancel" otherbuttontitle:@"ok", nil];      addsomethingalertviewstyle = uialertviewstyleplaintextinput;     [[addsomethingalertview textfieldatindex:0] setdelegate: self];     [[addsomethingalertview textfieldatindex:0] setkeyboardtype: uikeyboardtypedecimalpad];     [[addsomethingalertview textfieldatindex:0] becomefirstresponder];      [addsomethingalertview show]; }  -(void)initializeshowsomethingav {      showsomethingav = [[uialertview alloc] initwithtitle:@"show" message:@"show"     delegate:self cancelbuttontitle:@"cancel" otherbuttontitle:@"show", nil];      [showsomethingav show];   @end 

viewcontroller.h

#import"alertviews.h"  @interface viewcontroller: uiviewcontroller <uialertviewdelegate> {    alertviews *newalert;  alertviews *showalert;  }  @property (nonatomic, retain) alertviews *newalert; @property (nonatomic, retain) alertviews *newalert;  -(ibaction)adding:(id)sender; -(ibaction)showing:(id)sender; 

viewcontroller.m

@implementation @synthesize newalert = _newalert; @synthesize showalert = _showalert;  -(ibaction)adding:(id)sender {      [self.newalert = [[alertviews alloc] init];     [self.newalert initializeaddsomethingalertview]; }  -(ibaction)showing:(id)sender {      [self.showalert = [[alertviews alloc] init];     [self.showalert initializeshowsomethingav];  @end 

i tried implement code in viewcontroller.m

-(void)alertview:(uialertview *)alertview diddismisswithbuttonindex:(nsinteger)buttonindex  {     if (addsomethingalertview) {if (buttonindex == 1) { nslog(@"adding"); }     if (showsomethingav) {if (buttonindex == 1) {nslog(@"showing"); } } 

however, not log.

also, how can use text entered in alertview text field?

thanks!

please check whether able work after implementing below

- (void)alertview:(uialertview *)alertview clickedbuttonatindex:(nsinteger)buttonindex {     if (buttonindex == 0){       //cancel button clicked.      }     else{       //for getting text entered in alertview text field, need       uitextfield* yourtxt= [alertview textfieldatindex:0];       nsstring* txtcontent= yourtxt.text;      } }  

hope helps..


Comments

Popular posts from this blog

html - How to style widget with post count different than without post count -

How to remove text and logo OR add Overflow on Android ActionBar using AppCompat on API 8? -

javascript - storing input from prompt in array and displaying the array -