我正在开发我的第一个真正的 iPhone 应用程序,一个简单的待办事项列表应用程序来帮助我组织内容,但我收到了一个“无法识别的选择器发送到实例 0x”。
具体:
2010-02-20 14:30:09.200 ToDoApp[88562:20b] *** -[NSCFDictionary switchViews:]: unrecognized selector sent to instance 0x3d22de0
2010-02-20 14:30:09.201 ToDoApp[88562:20b] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '*** -[NSCFDictionary switchViews:]: unrecognized selector sent to instance 0x3d22de0'
我环顾四周,发现这可能是 IB 中的连接问题,但我对整个连接事物很陌生(伙计,我希望他们支持 Java 或 Python),所以这里是它的布局方式。我有 3 个类,一个 SwitchViewController、一个 MainScreenViewController 和一个 ToDoListViewController。当我点击 MainScreenViewController 上的按钮时,我触发了引发此问题的“switchViews”函数。我设置它的方式是按钮(UIBarButtonItem)具有“sentAction”转到switchViews。此 ViewButton 在 SwitchViewController 中将其引用 socket 作为 IBOutlet。
这是 SVC 的 .h:
#import <UIKit/UIKit.h>
@class MainScreenViewController;
@class ToDoListViewController;
@class EditViewController;
#define kMinimumGestureLength 25
#define kMaximumVariance 5
@interface SwitchViewController : UIViewController {
MainScreenViewController *mainScreenViewController;
ToDoListViewController *toDoListViewController;
EditViewController *editViewController;
IBOutlet UIBarButtonItem *viewButton;
CGPoint gestureStartPoint;
}
@property (retain, nonatomic) MainScreenViewController *mainScreenViewController;
@property (retain, nonatomic) ToDoListViewController *toDoListViewController;
@property (retain, nonatomic) EditViewController *editViewController;
@property (retain, nonatomic) IBOutlet UIBarButtonItem *viewButton;
@property CGPoint gestureStartPoint;
-(IBAction)switchViews:(id)sender;
对于 switchViews 函数:
-(IBAction) switchViews:(id)sender
{
NSLog(@"Switching views");
if(self.toDoListViewController.view.superview == nil){
if(self.toDoListViewController ==nil){
ToDoListViewController *toDoVC = [[ToDoListViewController alloc] initWithNibName:@"ToDoListView" bundle:nil];
self.toDoListViewController = toDoVC;
//[toDoVC release];
}
[mainScreenViewController.view removeFromSuperview];
[self.view insertSubview:toDoListViewController.view atIndex:0];
}
else{
if(self.mainScreenViewController == nil){
MainScreenViewController *mainController = [[MainScreenViewController alloc] initWithNibName:@"MainScreenView" bundle:nil];
self.mainScreenViewController = mainController;
//[mainController release];
}
[toDoListViewController.view removeFromSuperview];
[self.view insertSubview:mainScreenViewController.view atIndex:0];
}
}
总之,我完全迷失了,这真的很令人沮丧。有人有任何建议,或者需要更多代码吗?
最佳答案
我们刚刚遇到了同样的问题。看来我们在 AppDelegate 中释放了 ViewController 对象,然后我们的 nib View 尝试调用 IBAction (在 View Controller 上)。有一半的时间我们收到“EXC_BAD_ACCESS”(又名消息传递已释放的对象),一半的时间我们收到“无法识别的选择器发送到 NSCFString、NSCFArray 的实例”,以及各种各样的事情(又名消息传递已占用的内存区域)由不同的对象)。
只需检查您的 ViewController 是否尚未发布。
关于iPhone:IBAction 导致 "Unrecognized Selector Sent to Instance"错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2303416/