2

我为我的 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)

4

1 回答 1

2

欢迎!

是的,您应该为您的 Credits 创建一个单独的 .h / .m。然后告诉 Interface Builder 你的 .xib 是 Credits 类。然后使用您想要的操作将您的按钮链接到此 .h。基本上,您的最后一个方法应该在 Credits.m 中:

- (IBAction) toggleCreditsClosed:(id)inSender
{
    NSLog(@"Button Pressed!");
    [self dismissModalViewControllerAnimated:YES];
}

当心,您在代码中使用self而不是 self.parentViewController关闭模态视图!

(PS:你得到的答案可能并不总是有效。不要犹豫发表评论,告诉我们什么(没有)有效!)

于 2012-10-23T08:54:59.917 回答