2

新しい credits.xib を表示する infoButton のコードをいくつか見つけましたが、 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:]:

申し訳ありませんが、私は何をしなければならないのか理解できず、お見せする画像をアップロードすることはできませんが、アウトレットではリンクが (view<->View) であり、受信アクションでは (toggleCreditsClosed:<->Button-Done Touch Down) です。

4

1 に答える 1

2

SOへようこそ!

はい、クレジット用に別の .h / .m を作成する必要があります。次に、Interface Builder に、.xib が Credits クラスであることを伝えます。次に、必要なアクションを使用して、ボタンをこの .h にリンクします。基本的に、最後のメソッドは Credits.m にある必要があります:

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

コードで self.parentViewController の代わりにselfを使用してモーダル ビューを閉じることに注意してください。

(追伸: あなたが得た答えが常にうまくいくとは限りません。遠慮なくコメントして、何がうまくいかなかったのか教えてください!)

于 2012-10-23T08:54:59.917 に答える