Interface Builder 将看不到操作方法

发布于 2024-09-19 03:07:34 字数 354 浏览 4 评论 0原文

我正在尝试将 UIButton 连接到界面生成器中的 IBAction,但 IB 不会显示我定义为连接它的选项的方法。

- (IBAction)someAction:(id)sender;

这就是我在 h 文件中的内容,然后在 M 文件中我有

- (IBAction)someAction:(id)sender{
NSLog(@"Button Tapped.");   }

IB 文档连接到我知道的那个类,因为该类也有一个 UIPicker,并且连接良好。

任何帮助都会很棒,

谢谢, 卡拉汉001。

I am trying to hook up a UIButton to a IBAction in interface builder but IB will not show the method that I defined as an option to hook it up to.

- (IBAction)someAction:(id)sender;

That is what I have in the h file, and then in the M file I have

- (IBAction)someAction:(id)sender{
NSLog(@"Button Tapped.");   }

The IB Document is connected to that class i know because that class also has a UIPicker, and that connects fine.

Any help would be brilliant on this,

Thanks,
Callaghan001.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(6

别挽留 2024-09-26 03:07:34

我通过从 Interface Builder 手动读取类文件解决了这个问题。只需执行文件 ->读课->找到您在其中定义 IBAction 的 .h 文件。 ->打开!
然后界面构建器会说“解析了一个类文件”之类的内容

I fixed this problem by reading in the Class file manually from Interface Builder. Just do File -> Read Class -> find the .h file you defined the IBAction in. -> open!
Then Interface builder will say something like "one Class file parsed"

羅雙樹 2024-09-26 03:07:34

确保您实际上正在连接按钮事件的处理程序(可能在内部进行触摸)而不是按钮本身。因此,不要直接从按钮拖动,而是按住 Ctrl 键单击按钮以查看其连接,然后从其 touch up 内部事件拖动到目标,或者按住 Ctrl 键单击目标,找到操作,然后从该操作拖动到按钮。如果在这些情况下操作没有显示在目标上,并且您确定界面构建器知道它是什么类,那么我会感到困惑。

Make sure you're actually wiring up the handler for the button's event (probably touch up inside) and not the button itself. So instead of dragging directly from the button, either ctrl-click the button to see its connections and drag from its touch up inside event to the target, or ctrl-click the target, find the action, and drag from that to the button. If the action doesn't show up on the target in these cases, and you're sure interface builder knows what class it is, then I'm baffled.

尹雨沫 2024-09-26 03:07:34

同样的问题,读取类文件并没有解决它,但是将控制器身份检查器中的类名称从 UIViewController 更改为正确的子类名称却解决了这个问题。

same problem, reading class file in didn't fix it but changing the class name in the controller identity inspector from UIViewController to the correct subclass name did.

情魔剑神 2024-09-26 03:07:34

尝试在 .h 文件中添加 -(IBAction)testFunction:(id)sender;

这对我有用。

try adding -(IBAction)testFunction:(id)sender; in the .h file.

It worked for me.

独自唱情﹋歌 2024-09-26 03:07:34

我遇到了这个问题,重新启动 Xcode 并没有解决它。

为我解决的问题是:

  1. 选择文件所有者
  2. 转到身份检查器(在实用程序下,右侧面板)。
  3. 自定义类部分下,只需选择文本字段(其中应显示您的自定义UIViewController子类名称)并按“Enter”。

I had a this problem and restarting Xcode did not solve it.

What solved it for me was:

  1. Select File Owner
  2. Go to Identity Inspector (under Utilities, right hand side panel).
  3. Under Custom Class section, just select the text field (where your custom UIViewController sub-class name should be displayed) and hit 'Enter'.
番薯 2024-09-26 03:07:34

我认为你的实施必须是

- (void)someAction:(id)sender
{
    NSLog(@"Button Tapped.");   
}

I think your implementation must be

- (void)someAction:(id)sender
{
    NSLog(@"Button Tapped.");   
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文