【问题标题】:IOS. Unable to close view after clicking my Info button (newbie)IOS。单击我的信息按钮后无法关闭视图(新手)
【发布时间】:2012-10-23 08:47:39
【问题描述】:

我为我的 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 中,链接是 (viewView),在 Received Actions 中是 (toggleCreditsClosed:Button-Done Touch Down)

【问题讨论】:

    标签: ios5 modalviewcontroller


    【解决方案1】:

    欢迎!

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

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

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

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

    【讨论】:

    • 我有一个错误:int retVal = UIApplicationMain(argc, argv, nil, nil); -> 信号 SIGABRT。我已将 .xib 作为 Credits 类。网点是链接的(DoneButtonButton 和 viewview),并且在 receivedActions 我有(toggleCreditsClosedButton Touch Down)
    • 当我点击信息按钮,显示信用视图时出现错误
    • 确保删除之前使用 * toggleCreditsClosed:* 设置的链接。我不认为这是导致错误的原因,但这是我总是忘记的事情。这很可能来自于过多的 release。您应该确保在调用 [anObject release]; 时确实需要它。你能用堆栈跟踪更新你的问题吗?
    • 检查您的 DoneButton。我认为您之前从 xib 到 .h 创建了一个 IBOutlet,然后在代码中将其删除,因此链接仍然存在。尝试记住您在哪里使用该变量名称并选择 xib。然后转到右侧栏中的最后一个选项卡并删除链接。如果你找到了,请告诉我!
    • 堆栈跟踪已上传。我被困住了。感谢您的耐心等待。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-12-14
    • 1970-01-01
    • 2016-09-28
    • 1970-01-01
    • 2017-02-27
    相关资源
    最近更新 更多