0

ボタンを処理する新しいクラスを作成しました。それは何もしません(テストのためだけに、メソッドはクリーンです)。起動直後に割り当てが解除され、ボタンをクリックするとアプリがEXC_BAD_ACCESSでクラッシュします。これは、クラスの私の.hファイルです。

@interface pagechanger : NSObject {
}
- (IBAction)gonext:(id)sender;
@end

実装ファイル:

@implementation pagechanger
- (IBAction)gonext:(id)sender{
// blablabla, some code which is even hasn't been read, breakpoints were not touched.
}

-(void)dealloc{
    NSLog(@" pc released");
    [super dealloc];
}
@end

コンソールリスト(NSZombieEnabledがオンになっている):

[11724:207] * -[pagechanger PerformSelector:withObject:withObject:]:割り当て解除されたインスタンス0x4b35900に送信されたメッセージ

これは、「infomalloc-historyaddress」が返すものです

Alloc: Block address: 0x04b35900 length: 16
Stack - pthread: 0xa0180540 number of frames: 36
    0: 0x9154e103 in malloc_zone_calloc
    1: 0x9154e05a in calloc
    2: 0x105cd0f in _internal_class_createInstanceFromZone
    3: 0x105f87d in class_createInstance
    4: 0xe2cff8 in +[NSObject(NSObject) allocWithZone:]
    5: 0xe2cdfa in +[NSObject(NSObject) alloc]
    6: 0x4ab205 in -[UIClassSwapper initWithCoder:]
    7: 0x5919e4 in UINibDecoderDecodeObjectForValue
    8: 0x592693 in -[UINibDecoder decodeObjectForKey:]
    9: 0x4aaf43 in -[UIRuntimeConnection initWithCoder:]
   10: 0x4ab4b1 in -[UIRuntimeEventConnection initWithCoder:]
   11: 0x5919e4 in UINibDecoderDecodeObjectForValue
   12: 0x5912dc in UINibDecoderDecodeObjectForValue
   13: 0x592693 in -[UINibDecoder decodeObjectForKey:]
   14: 0x4aa200 in -[UINib instantiateWithOwner:options:]
   15: 0x4ac081 in -[NSBundle(UINSBundleAdditions) loadNibNamed:owner:options:]
   16: 0x364a94 in -[UIViewController _loadViewFromNibNamed:bundle:]
   17: 0x362709 in -[UIViewController loadView]
   18: 0x2607 in -[ZoomingPDFViewerViewController loadView] at /Users/ruzard/Desktop/ZoomingPDFViewer/Classes/ZoomingPDFViewerViewController.m:92
   19: 0x3625e3 in -[UIViewController view]
   20: 0x2231 in -[ZoomingPDFViewerAppDelegate application:didFinishLaunchingWithOptions:] at /Users/ruzard/Desktop/ZoomingPDFViewer/Classes/ZoomingPDFViewerAppDelegate.m:65
   21: 0x2b51fa in -[UIApplication _callInitializationDelegatesForURL:payload:suspended:]
   22: 0x2b755e in -[UIApplication _runWithURL:payload:launchOrientation:statusBarStyle:statusBarHidden:]
   23: 0x2c1db2 in -[UIApplication handleEvent:withNewEvent:]
   24: 0x2ba202 in -[UIApplication sendEvent:]
   25: 0x2bf732 in _UIApplicationHandleEvent
   26: 0x183ea36 in PurpleEventCallback
   27: 0xeea064 in __CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE1_PERFORM_FUNCTION__
   28: 0xe4a6f7 in __CFRunLoopDoSource1
   29: 0xe47983 in __CFRunLoopRun
   30: 0xe47240 in CFRunLoopRunSpecific
   31: 0xe47161 in CFRunLoopRunInMode
   32: 0x2b6fa8 in -[UIApplication _run]
   33: 0x2c342e in UIApplicationMain
   34: 0x21c4 in main at /Users/ruzard/Desktop/ZoomingPDFViewer/main.m:54
   35: 0x2155 in start

Appleのコード(ZoomingPDFViewer)を変更しようとしています。そこに新しいボタンを追加する方法が見つかりませんでした...そこで、プログラムで新しいウィンドウを作成し、それにサブビューを追加しました。しかし、このコードが役立つかどうかはわかりません...

    UIWindow* window = [UIApplication sharedApplication].keyWindow;
if (!window) {
    window = [[UIWindow alloc] initWithFrame:CGRectMake(0, 980, 500, 500)];
    window.hidden = NO;
    [window becomeKeyWindow];
    window.windowLevel = UIWindowLevelStatusBar;
}
[window addSubview:myheader];

ここで元のコードを取得できます。

EXC_BAD_ACCESSなしでメソッドを機能させるにはどうすればよいですか?

4

1 に答える 1

1

解決策はこれに帰着します:

pagechangerこの場合、インスタンスの存続期間を管理する責任は何ですか?ターゲット/アクションを使用する場合、ターゲットは呼び出し側によって保持されません。pagechangerしたがって、ターゲットが呼び出し元に登録されている間、参照を保持するための何かが必要になります。

=====

詳細については、特定の問題の詳細の診断を開始するのに十分な関連コードが投稿されていません。

于 2011-02-06T04:47:29.767 に答える