如何从ID获取Interface Builder名称 [英] How to get Interface Builder name from id

查看:58
本文介绍了如何从ID获取Interface Builder名称的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如果我在Interface Builder中命名一个小部件,然后编写一个方法来接收该按钮上的点击事件:

If I name a widget in Interface Builder, and then I write a method that receives click events on that button:

- (IBAction)btnTouchDown:(id)sender
{
  // how can you identify the button here,
  // if several different buttons map
  // their "Touch" event to this same function?
  // I know you can look at its text but that seems really clumsy
  // can I somehow get its INTERFACE BUILDER NAME?

  // I named each uniquely in interface builder,
  // under "Identity"/"Name"
  // Or is my only recourse to tie EACH BUTTON to its own handler function?
}

推荐答案

单击界面生成器中的按钮,按CMD + 2(或在信息对话框的第二个选项卡中),然后从在内部向上触摸转到yourView.xib窗口中的文件所有者,然后让您选择一种具有- (IBAction) method:(id)sender签名的方法.选择要与该按钮关联的按钮:)

Click on the button in interface builder, press CMD+2 (Or in info dialog, second tab) and drag the circle from Touch up inside to File's Owner from the yourView.xib window and then it'll let you select one of the methods which has the - (IBAction) method:(id)sender signature. Choose the one you want to associate with that button :)

您说您不想为每个按钮创建一个方法,但是实际上,这是我认为的最佳方法,而不是拥有一个庞大的整体方法来处理每个按钮并每次检查以查看哪个按钮其中是.使用上面提到的过程,您可以将处理程序方法专门绑定到特定的按钮,以使事情保持美观,整洁和合乎逻辑.

You say you don't want to make a method for each button, but actually that is the best way in my opinion, rather than having one huge monolithic method which handles each of the buttons and checks each time to see which one of them it is. Using the process I mentioned above, you can specifically tie a handler method to a particular button, keeping things nice, tidy, and logical.

但是,如果您确实想这样做,也可以测试标签号.

If you really want to do that though, you can also test for the tag number.

这篇关于如何从ID获取Interface Builder名称的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆