【发布时间】:2012-10-10 01:33:01
【问题描述】:
我正在使用 Xcode 4.3.2。
我是 Xcode 的新手。我正在构建一个应用程序,该应用程序必须在单击按钮时更改为不同的视图。我的文件是:AppDelegate.h/.m、GreenViewController.h/.m、SwitchViewController.h/.m、GreenView.xib - 我没有使用故事板,但我的项目要求我不使用它们(向后兼容性问题)。
这是我的问题(看起来很简单):我试图在单击 UIButton(放置在 GreenView.xib 中)时打印到控制台。这是我的 GreenViewController.h 代码
#import <UIKit/UIKit.h>
@interface GreenViewController : UIViewController
- (IBAction)switchViews:(id)sender;
@end
这是我的 GreenViewController.m(已弃用)代码:
#import "GreenViewController.h"
@implementation GreenViewController
- (IBAction) switchViews:(id)sender {
NSLog(@"Button Pressed!");
}
GreenView.xib 的所有者是 GreenViewController。
由于某种原因,我只有在按下 UIButton(在 GreenView.xib 中)时才会出现错误:
2012-10-09 18:07:38.490 MyViewSwitcher[8655:f803] -[SwitchViewController switchViews:]: unrecognized selector sent to instance 0x688a660
2012-10-09 18:07:38.492 MyViewSwitcher[8655:f803] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[SwitchViewController switchViews:]: unrecognized selector sent to instance 0x688a660'
似乎 SwitchViewController 期望从方法“switchViews”中得到一些东西,但“switchViews”只在 GreenViewController 中列出。之前,我在 SwitchViewController 中有“switchViews”,但是我删除了与方法和所有连接对应的所有代码。同样,我再次检查了 GreenViewController 中的“switchViews”是否连接到 GreenView.xib 中的 UIButton。我已经清理并重新构建了我的项目,但仍然出现此错误。
感谢您的帮助!
【问题讨论】:
标签: iphone objective-c xcode cocoa ibaction