简体   繁体   English

iOS按钮无法点击-菜鸟问题

[英]ios button doesn't tap - noob issue

So I'm a new ios developer and am working on my first app. 因此,我是一名新的ios开发人员,正在开发我的第一个应用程序。 I have a 3d game in unity that I exported as an xcode project and my goal is to add an ios menu before accessing the game. 我有一个统一的3d游戏,我将其导出为xcode项目,我的目标是在访问游戏之前添加ios菜单。 Suffice it to say, I'm struggling with this. 可以说,我为此感到挣扎。 I've watch some of the stanford tutorials (great!), and read some tutorials I thought was applicable, but I'm stuck. 我看过斯坦福大学的一些教程(很棒!),并阅读了一些我认为适用的教程,但我陷入了困境。 Here's what I've got: 这是我得到的:

I hijacked the main.m file to load myAppDelegate (instead of the one Unity made). 我劫持了main.m文件来加载myAppDelegate(而不是一个Unity)。 myAppDelegate then loads an instance of myViewController and adds it as a subview to the window. 然后,myAppDelegate加载myViewController的实例,并将其作为子视图添加到窗口。 In the myViewController, I have: 在myViewController中,我有:

-(IBAction) displayView:(id) sender{
 UIAlertView *alert = [[UIAlertView alloc] 
 initWithTitle:@"Button Pressed" 
 message:@"You have pressed the Button view."
 delegate:nil
 cancelButtonTitle:@"OK" 
 otherButtonTitles:nil];
 [alert show];
 [alert release];   
}

I'm just trying to issue an alert on a button click. 我只是想在单击按钮时发出警报。 I have the function defined in the .h file with -(IBAction) displayView:(id) sender; 我在.h文件中使用-(IBAction) displayView:(id) sender;定义了该函数-(IBAction) displayView:(id) sender;

On the view side of things, I added an entry to my plist file I have Main Nib File Base Name set to MainWindow. 从视图的角度来看,我在plist文件中添加了一个条目,将Main Nib File Base Name设置为MainWindow。

Then in the Interface Builder, in MainWindow.xib, I had added from the Library, myAppDelegate and myViewController. 然后在Interface Builder的MainWindow.xib中,我从库中添加了myAppDelegate和myViewController。 For myAppDelegate, I added myViewController as the viewController delegate, window is Window, and the reference outlet is the file owner. 对于myAppDelegate,我添加了myViewController作为viewController委托,window是Window,参考出口是文件所有者。 For myViewController, the referencing outlet is the myAppDelegate. 对于myViewController,引用出口是myAppDelegate。 (To be honest, this part confuses me. It doesn't have much of a corollary to my php web app background.) (说实话,这部分使我感到困惑。它对我的php Web应用程序背景没有太大的推论。)

In myViewController.xib, the File Owner is myViewController. 在myViewController.xib中,文件所有者是myViewController。 Received action shows a link from my function (displayView) to a button. 收到的动作显示了我的函数(displayView)到按钮的链接。 Then for the view, I opened that up, painted it red and littered it with general ios widgets (buttons, datepickers, etc). 然后,对于视图,我将其打开,将其涂成红色,并用常规的ios小部件(按钮,日期选择器等)乱扔它。 I hooked up one of the buttons to have a touch up inside of displayView. 我连接了其中一个按钮以在displayView内部进行修饰。

So that's all that I've done, I load up the app on my device and I see exactly what I laid out on view. 这样就完成了,我在设备上加载了该应用程序,并看到了所显示的内容。 But nothing is intractable. 但是没有什么是棘手的。 I expect taping my button to show the alert defined above. 我希望点击我的按钮以显示上面定义的警报。 But that doesn't happen. 但这不会发生。 In fact nothing happens. 实际上什么也没发生。 So I suspect the hooking of all of this up is incorrect. 所以我怀疑所有这些都是不正确的。 But the button doesn't even depress? 但是按钮甚至没有按下? I would expect the white button to flash blue (down state) when I tap it. 我希望白色按钮在点击时会闪烁蓝色(按下状态)。 Further, I would expect the date picker (not hooked up to function), to spin as I interact with it. 此外,我希望日期选择器(不连接功能)在与之交互时旋转。

It's as if my touches aren't getting sent to the view. 好像我的触摸没有被发送到视图。 Does anybody have any idea what I might be doing wrong? 有人知道我在做什么错吗? Thanks in advance for your help! 在此先感谢您的帮助!

Try this code: 试试这个代码:

-(IBAction) displayView:(id) sender{

UIAlertView * myAlert;

myAlert = [[UIAlertView alloc]initWithTitle:@"Button Pressed" 
  message:@"You have pressed the Button view."
  delegate:nil
  cancelButtonTitle:@"OK" 
  otherButtonTitles:nil];

 [myAlert show]; 
 /* And make sure to have this action connected to your button in xib           
 file */

}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM