在视图之间转换时的 Objective-C 问题
我在视图之间转换时遇到问题,需要一些帮助。这有点令人费解,所以请耐心等待。
我有一个名为 JobsNavController
的 UINavigationController。 JobsNavController 中的第一个视图包含一个名为 JobsTableViewController
的 UITableViewController [带有名为 JobTableView.xib
的链接笔尖]。我想在 UINavController 内添加一个 Add
UIButton 来“创建新作业”。单击时,它应该从 JobTableView.xib
翻转到我的名为 JobCreateView.xib
的 JobCreateViewController
笔尖。由于“添加”按钮位于 UINavController 内,因此我将 IBAction 代码放入 JobsNavController.h 和 .m
内。
这是 JobsNavController.h
#import <UIKit/UIKit.h>
@class JobCreateViewController, JobsTableViewController;
@interface JobsNavController : UINavigationController {
IBOutlet UIButton *btnJobCreate;
IBOutlet JobCreateViewController *jobCreateViewController;
IBOutlet JobsTableViewController *jobsTableViewController;
}
-(IBAction)tellDelegateToFlip:(id)sender;
@property (nonatomic, retain) UIButton *btnJobCreate;
@property (nonatomic, retain) IBOutlet JobCreateViewController *jobCreateViewController;
@property (nonatomic, retain) IBOutlet JobsTableViewController *jobsTableViewController;
@end
这是我的 JobsNavController.m
#import "JobsNavController.h", "Time_Blogger1AppDelegate.h", "JobsTableViewController.h"
@implementation JobsNavController
@synthesize btnJobCreate, jobCreateViewController, jobsTableViewController;
.....
-(void)tellDelegateToFlip {
JobCreateViewController *jobAddView = [jobCreateViewController initWithNibName:@"JobCreateView" bundle:nil];
[self setJobCreateViewController:jobAddView];
[jobAddView release];
UIViewController *transitionTo = jobCreateViewController;
//create view animation block
[UIView beginAnimations:nil context:NULL];
[UIView setAnimationDuration:1.25];
[UIView setAnimationTransition:UIViewAnimationTransitionFlipFromLeft forView:self.view cache:YES];
[jobsTableViewController.view removeFromSuperview];
[self.view insertSubview:transitionTo.view atIndex:0];
[UIView commitAnimations];
[transitionTo release];
}
我没有收到任何构建/编译错误,但当我单击按钮时模拟器会抛出异常,说明:
2012-01-22 19:19:22.895 Time-Blogger1[4209:f803]
-[JobsNavController tellDelegateToFlip:]: unrecognized selector sent to instance 0x6c85e80 2012-01-22 19:19:22.897 Time-Blogger1[4209:f803]
*** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason:
'-[JobsNavController tellDelegateToFlip:]: unrecognized selector sent to instance 0x6c85e80'
I'm having issues transitioning between views and need some help. This is somewhat conviluted so bear with me please.
I have a UINavigationController called JobsNavController
. The first view in JobsNavController holds a UITableViewController called JobsTableViewController
[with a linked nib called JobTableView.xib
]. I want to add an Add
UIButton inside the UINavController to 'create a new job'. When clicked, it should flip from JobTableView.xib
to my JobCreateViewController
nib called JobCreateView.xib
. Since the 'add' button is located within the UINavController I put the IBAction code inside JobsNavController.h and .m
.
Here is the JobsNavController.h
#import <UIKit/UIKit.h>
@class JobCreateViewController, JobsTableViewController;
@interface JobsNavController : UINavigationController {
IBOutlet UIButton *btnJobCreate;
IBOutlet JobCreateViewController *jobCreateViewController;
IBOutlet JobsTableViewController *jobsTableViewController;
}
-(IBAction)tellDelegateToFlip:(id)sender;
@property (nonatomic, retain) UIButton *btnJobCreate;
@property (nonatomic, retain) IBOutlet JobCreateViewController *jobCreateViewController;
@property (nonatomic, retain) IBOutlet JobsTableViewController *jobsTableViewController;
@end
And here is my JobsNavController.m
#import "JobsNavController.h", "Time_Blogger1AppDelegate.h", "JobsTableViewController.h"
@implementation JobsNavController
@synthesize btnJobCreate, jobCreateViewController, jobsTableViewController;
.....
-(void)tellDelegateToFlip {
JobCreateViewController *jobAddView = [jobCreateViewController initWithNibName:@"JobCreateView" bundle:nil];
[self setJobCreateViewController:jobAddView];
[jobAddView release];
UIViewController *transitionTo = jobCreateViewController;
//create view animation block
[UIView beginAnimations:nil context:NULL];
[UIView setAnimationDuration:1.25];
[UIView setAnimationTransition:UIViewAnimationTransitionFlipFromLeft forView:self.view cache:YES];
[jobsTableViewController.view removeFromSuperview];
[self.view insertSubview:transitionTo.view atIndex:0];
[UIView commitAnimations];
[transitionTo release];
}
I'm not getting any build/compile errors but the simulator throws an exception when I click the button stating:
2012-01-22 19:19:22.895 Time-Blogger1[4209:f803]
-[JobsNavController tellDelegateToFlip:]: unrecognized selector sent to instance 0x6c85e80 2012-01-22 19:19:22.897 Time-Blogger1[4209:f803]
*** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason:
'-[JobsNavController tellDelegateToFlip:]: unrecognized selector sent to instance 0x6c85e80'
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
当您调用
tellDelegateToFlip
时,请确保您没有使用任何参数 - 这就是导致崩溃的原因。如果您在崩溃报告中注意到,它表示无法识别的选择器tellDelegateToFlip:
正在发送到您的实例。请注意方法名称后面的冒号。这意味着无论您在哪里调用该方法,都会随之发送一个对象。如果您使用performSelector:withObject:afterDelay:
,请确保您不使用冒号。编辑:
而不是:
为什么不直接使用:
或者您可以强制转换它,假设
JobCreateViewController
继承自 UIViewController。When you call
tellDelegateToFlip
make sure you do it with no parameters- this is what is causing the crash. If you notice in the crash report, it says the unrecognized selectortellDelegateToFlip:
is being sent to your instance. Notice the colon coming after the method name. This means that wherever you called the method, you sent an object with it. If you are usingperformSelector:withObject:afterDelay:
make sure you don't use a colon.Edit:
Instead of:
why don't you just use:
Or you could cast it, assuming that
JobCreateViewController
inherits from UIViewController.该方法的错误实现:
应该是:
在您的 JobsNavController.m 中
wrong implementation of the method:
should be:
in your JobsNavController.m