iPhone:IBAction导致"无法识别的选择器发送到实例"错误

Alt*_*ane 3 iphone interface-builder selector ibaction

我正在开发我的第一个真正的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'
Run Code Online (Sandbox Code Playgroud)

我环顾四周,发现它可能是IB中的一个连接问题,但我对这整个连接事物都是新手(男人,我希望他们支持Java或Python),所以这里是如何布局的.我有3个类,一个SwitchViewController,一个MainScreenViewController和一个ToDoListViewController.当我点击MainScreenViewController上的一个按钮时,我触发了"switchViews"函数,这个函数引发了这个问题.他们设置的方式是按钮(一个UIBarButtonItem)将"sentAction"转到switchViews.这个ViewButton的参考出口作为SwitchViewController中的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;  
Run Code Online (Sandbox Code Playgroud)

而对于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];
 }
}
Run Code Online (Sandbox Code Playgroud)

所以简而言之,我完全迷失了,这真的令人沮丧.任何人有任何建议,还是需要更多代码?

dia*_*lic 12

我们遇到了同样的问题.看来我们在AppDelegate中发布了ViewController对象,然后我们的nib视图尝试调用IBAction(在视图控制器上).有一半时间我们得到"EXC_BAD_ACCESS"(也就是发布对象的消息),有一半时间我们得到了"无法识别的选择器发送到实例"的NSCFString,NSCFArray,各种各样的东西(也就是消息现在占用的内存区域)由不同的对象).

只检查您的ViewController尚未发布.