ios - Tracking which UIAlert button is clicked to change UILabel -


i'm complete beginner , looking learn how start coding build own apps. i've been messing around classic "hello world" design , trying improve on based on limited knowledge have managed gather in past week i've got stuck , hope can me out!

so far have uitextfield user enter name, label display name , button update display. understand uialertviews better have included alert if name entered chris (or chris) , alert if name entered not chris. functioning fine far.

i'm looking track button pressed on incorrectname uialertview , update uilabel "chris" if click "i want called chris" button. have build app similar before tutorial , have copied across code thought should function same doesnt seem work.

here .m file far

#import "solo1viewcontroller.h"  @interface solo1viewcontroller ()  @end  @implementation solo1viewcontroller  @synthesize setmessage; @synthesize username;  -(void)alertview:(uialertview *)alertview clickedbuttonatindex:(nsinteger)buttonindex {     nsstring *buttontitle=([alertview buttontitleatindex:buttonindex]);     if ([buttontitle isequaltostring:@"i want called chris!"])     {setmessage.text=@"chris";} }  -(ibaction)showmessage:(id)sender {     setmessage.text=username.text;      if ([username.text isequal:@"chris"] || [username.text isequal:@"chris"])         {         uialertview *correctname;         correctname = [[uialertview alloc]initwithtitle:@":)" message:@"great name!" delegate:nil cancelbuttontitle:@"bye fellow chris" otherbuttontitles:nil, nil];         [correctname show];         }     else         {             uialertview *incorrectname;             incorrectname=[[uialertview alloc] initwithtitle:@":(" message:@"chris better name" delegate:nil cancelbuttontitle:@"no, thanks" otherbuttontitles:@"i want called chris!", nil];             [incorrectname show];         } }  -(ibaction)removekeyboard:(id)sender{     [username resignfirstresponder]; } 

to me seems though should work guess i'm missing glaringly obvious or i'm doing totally wrong.

make sure set alert view's delegate self! right have delegate set nil.

example:

incorrectname=[[uialertview alloc] initwithtitle:@":(" message:@"chris better name" delegate:self cancelbuttontitle:@"no, thanks" otherbuttontitles:@"i want called chris!", nil]; 

Comments

Popular posts from this blog

javascript - Jquery show_hide, what to add in order to make the page scroll to the bottom of the hidden field once button is clicked -

javascript - Highcharts multi-color line -

javascript - Enter key does not work in search box -