开发者

how to access buttons events from controller objective-c

I just started to learn Objective-C and iPhone SDK programming. I have made 2 rect buttons and one label in my XIB design (it is appearing after clicking on views). I have to make code in button click event in my 开发者_如何学JAVAcontroller. As in c#.net we simply take button.click event (dummy code).

Like I have 2 rect buttons and their title is 8 and 9 and one label. When I will click on button 8 my label will print 8 and similarly when I will click on button 9 my label will show 9. My concern is that is how will know in controller (.m file) which button is being pressed.


Set the tag field of your buttons to different values, then define a method

-(IBAction)buttonPressed:(id)sender;

and inside it call [(UIView *)sender tag]. Checking that value you will know what button has been pressed.

Alternatively you may call two different methods, but since the behavior is such similar I'd prefer the first solution.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜