ios - Cannot connect to each button of alert and action sheet in Xcode 5 and Objective-C -


first, in following header file:

#import <uikit/uikit.h>  @interface viewcontroller : uiviewcontroller <uiactionsheetdelegate> - (ibaction)btnsheet1:(id)sender; @property (weak, nonatomic) iboutlet uilabel *mylabel;  -(void) actinsheet:(uiactionsheet *) actionsheet clickedbuttonatindex:(nsinteger)buttonindex; @end 

and implementation file:

 #import "viewcontroller.h"  @implementation viewcontroller  - (ibaction)btnsheet1:(id)sender  {     uiactionsheet *sheet = [[uiactionsheet alloc] initwithtitle:@"action" delegate:self cancelbuttontitle:@"cancel" destructivebuttontitle:@"do it!" otherbuttontitles:@"other button", nil];     sheet.actionsheetstyle = uiactionsheetstyleblacktranslucent;     [sheet showinview:self.view]; }  -(void) actinsheet:(uiactionsheet *) actionsheet clickedbuttonatindex:(nsinteger)buttonindex {     if(buttonindex == 0)     {         self.mylabel.text = [nsstring stringwithformat:@"button: %d pressed", buttonindex];     }      else if (buttonindex == 1)     {         self.mylabel.text = [nsstring stringwithformat:@"button: %d pressed", buttonindex];     } }   @end 

when ran simulator, button , label shown on screen. however, when clicked on button have action sheet popped up, , tried press 1 of buttons in order make mylabel changed other strings, label didn't change...

i tried same thing on alert view, didn't work too.

so why code not work? entire snippets this book , book assumes use ios 6 , xcode 4, use ios 7 , xcode 5, may culprit?

for information, connected label iboutlet, , button ibaction, aforementioned book does.

thanks.

it not work, writing delegate wrong:

-(void) actinsheet:(uiactionsheet *) actionsheet clickedbuttonatindex:(nsinteger)buttonindex 

it should actionsheet.

-(void) actionsheet:(uiactionsheet *) actionsheet clickedbuttonatindex:(nsinteger)buttonindex 

Comments

Popular posts from this blog

java.util.scanner - How to read and add only numbers to array from a text file -

rewrite - Trouble with Wordpress multiple custom querystrings -