Which button was tapped… iPhone and Obj-C question

Which button was tapped… iPhone and Obj-C question

I'm a newbie just begun with iPhone and Obj-C for a month now.

I have two buttons, both of them call the same function as follows

[play addTarget:self action:@selector(showQstn:) forControlEvents:UIControlEventTouchUpInside]; 

Inside the function showQstn, I want to know what button was tapped. Any idea? Alternate ideas are welcome too.


Can we run Java applictions on iPhone? [closed]


What's a Java alternative to Google App Engine for developing iPhone Push Notification services?
Assuming this showQstn: is declared as. Running JavaScript in a UIWebView before any other JavaScript is run
-(void) showQstn:(id)sender; 
The argument sender is the trigger object of the event.. UIScrollView image/photo viewer with paging enabled and zooming EDIT: You must also distinguish between the although tons using the tag property. Creating the Iphone MapKit showUserLocation Ring Annimation Each view has a unique tag identifier (which must be set programatically or through Interface Builder).. Upload and download data from server with Cocoa Touch? EDIT: UIButton does not have a title property, hence you receive ting the error. How do I lock the orientation to portrait mode in a iPhone Web Application? It has a titleForState:. How do I make a button play sounds in a certain order using an array? So you should change your code to the following:.
NSString *title = [sender titleForState:UIControlStateNormal]; if ([title isEqualToString:@"PLAY!"]) {   name.text = title; } 


You receive the clicked although ton as the argument to your IBAction method showQstn:. You might consider setting the tag on the although tons, then using [sender tag] to identify which one triggered the IBAction method..

66 out of 100 based on 61 user ratings 236 reviews