我为我的 infoButton 找到了一些代码,它显示了我的新 credits.xib 但我无法回到我的 RootViewController。在我的 Credits.xib 上,我已将“完成”按钮与 ToucheDown-FirstResponder-ToggleCredits Close 相关联。
这是我在 ViewDidLoad 中的 RootViewController.m 中的 infoButton 代码
UIButton *button = [UIButton buttonWithType:UIButtonTypeInfoLight];
[button addTarget:self action:@selector(toggleCreditsOpen:) forControlEvents:UIControlEventTouchUpInside];
UIBarButtonItem *modalButton = [[UIBarButtonItem alloc] initWithCustomView:button];
[self.navigationItem setRightBarButtonItem:modalButton animated:YES];
//[button release];
[modalButton release];
我的代码就在我的 ViewDidLoad 之后
- (IBAction) toggleCreditsOpen:(id)inSender
{
UIViewController *theController = [[UIViewController alloc] initWithNibName:@"Credits" bundle:nil];
[self.navigationController presentModalViewController:theController animated:YES];
}
- (IBAction) toggleCreditsClosed:(id)inSender
{
NSLog(@"Button Pressed!");
//[self.navigationController dismissModalViewControllerAnimated:YES];
[self.parentViewController dismissModalViewControllerAnimated:YES];
}
我想我应该创建一个 Credits.h 并将 toggleCreditsClosed 放入其中吗?
这是堆栈跟踪
*** Terminating app due to uncaught exception 'NSUnknownKeyException', reason: '[<UIViewController 0x7c67610> setValue:forUndefinedKey:]: this class is not key value coding-compliant for the key DoneButton.'
*** First throw call stack:
这是我的 Credits.h
#import <UIKit/UIKit.h>
@interface Credits : UIViewController
{
IBOutlet UIButton *DoneButton;
}
@property (nonatomic, retain) UIButton *DoneButton;
@end
和我的 Credits.m
#import "Credits.h"
@implementation Credits
@synthesize DoneButton;
- (void)viewDidLoad
{
[super viewDidLoad];
}
- (void)viewDidUnload
{
}
- (IBAction) toggleCreditsClosed:(id)inSender
{
NSLog(@"Button Pressed!");
[self dismissModalViewControllerAnimated:YES];
}
@end
如果删除 DoneButton 链接,则会显示 Credits 视图,但我是在按下 Done 按钮时出现问题
Costumes[402:11f03] -[UIViewController toggleCreditsClosed:]: unrecognized selector sent to instance 0x7a4c460
2012-10-24 22:19:33.271 Costumes[402:11f03] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[UIViewController toggleCreditsClosed:]:
抱歉,但我不明白我必须做什么,我无法上传图片给你看,但在 Outlets 中,链接是(查看<->查看)和收到的操作(toggleCreditsClosed:<->Button-Done Touch Down)