如何将IBAction分配给第二个ViewController?(How do I assign an IBAction to a second ViewController?)

编程入门 行业动态 更新时间:2024-10-14 12:24:12
如何将IBAction分配给第二个ViewController?(How do I assign an IBAction to a second ViewController?)

我有两个ViewControllers这个项目。 这很简单。 在第二个窗口中,我只需要一个按钮来执行操作(链接到iTunes商店)。 我将代码添加到我的.h和.m文件中,但是无法在第二个窗口中将操作链接到我的按钮。 但我可以进入第一个...我发誓我冲浪和搜索但我找不到这样的答案。 应该很容易,不应该吗? 大家好!

I have this project with two ViewControllers. It´s very simple. In the second window I only want a button to perform an action (link to iTunes store). I´m adding the code to my .h and .m files, but it´s not possible to link the actions to my button in the second window. But I can into the first one… I swear that I surfed and searched but I can´t find an answer to something like this. Should be easy, shouldn´t it? Thanx everybody!!

最满意答案

如果在一个ViewController中创建IBAction ,则从另一个ViewController中将无法看到它。 这只是ViewControllers的本质。 如果你愿意,你可以使第二个类继承方法和变量形成另一个。 您可以通过替换来完成此操作

@interface SecondViewController: UIViewController {

@interface SecondViewController: FirstViewController {

在SecondViewController.h中

(如果出现错误,请在类的最顶部添加#import "FirstViewController.h" )

If you create an IBAction in one ViewController, it will not be visible from the other. This is just the nature of ViewControllers. If you want to, you can make the second class inherit the methods and variables form the other. You can do this by replacing

@interface SecondViewController: UIViewController {

with

@interface SecondViewController: FirstViewController {

in SecondViewController.h

(and if you get an error, add #import "FirstViewController.h" at the very top of the class)

更多推荐

本文发布于:2023-07-30 18:28:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1338875.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:第二个   如何将   assign   IBAction   ViewController

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!