1

テーブルのデリゲート メソッドを処理するクラスがあります。IB を使用し、クラスに変更した UITableViewDelegate を NIB にドラッグしました。また、UITableView オブジェクトを NIB に含め、ここでデリゲートと dataSource を TableViewDelegate クラスに接続します。

私のクラスはインターネットからテーブル データを取得するため、ビュー デザインで一度呼び出されたデリゲート メソッドを取得し、データがまだ到着していないためカウント 0 を返します。すべてのデータの取得が完了したら、[myTable reloadData] を実行し、デリゲート メソッドを再度呼び出します。問題は、numberOfRowsInSection が呼び出されることです。ここで、行数が返されますが、cellForRowAtIndexPath が呼び出されることはなく、代わりに EXC_BAD_ACCESS が返されます。スタック履歴とゾンビを有効にした後、クラスの割り当て解除が呼び出されていることがわかりました。

dealloc restTable クラス - dealloc メソッド内の NSLOG で生成されます。

2011-02-27 00:33:59.979 PesquisaMapa[3526:207] * -[restTable tableView:cellForRowAtIndexPath:]: 割り当て解除されたインスタンス 0x5624190 に送信されたメッセージ オブジェクトは最初に IB で作成され、それに対する IBOutlet がメインで宣言されているためクラス ヘッダー ファイルが削除され、アプリケーションが終了したときにのみ割り当てが解除されるため、クラスのこのインスタンスが割り当て解除される理由が本当にわかりません。私のスタックは次のとおりです。

(gdb) info malloc-history 0x5624190 Alloc: Block address: 0x05624190 length: 160 Stack - pthread: 0xa0a5f540 number of frames: 34 0: 0x9876f103 in malloc_zone_calloc 1: 0x9876f05a in calloc 2: 0x110ad0f in _internal_class_createInstanceFromZone 3: 0x110d87d in class_createInstance 4: 0xedaff8 +[NSObject(NSObject) allocWithZone:] 5: 0xedadfa in +[NSObject(NSObject) alloc] 6: 0x4c1205 in -[UIClassSwapper initWithCoder:] 7: 0x5a79e4 in UINibDecoderDecodeObjectForValue 8: 0x5a8693 in -[UINibDecoder decodeObjectForKey:] 9: 0x4c0f43 -[UIRuntimeConnection initWithCoder:] で 10: UINibDecoderDecodeObjectForValue で 0x5a79e4 11: UINibDecoderDecodeObjectForValue で 0x5a72dc: -[UINibDecoder decodeObjectForKey:] で 0x5a8693: -[UINib instanceiateWithOwner:options:] で 0x4c0200 14:0x4c2081 in -[NSBundle(UINSBundleAdditions) loadNibNamed:owner:options:] 15: 0x37aa94 in -[UIViewController _loadViewFromNibNamed:bundle:] 16: 0x378709 in -[UIViewController loadView] 17: 0x3785e3 in -[UIViewController view] 18: 0x22fe in - /Users/pcasqueiro/Documents/PesquisaMapaAppDelegate.m:24 で [PesquisaMapaAppDelegate アプリケーション:didFinishLaunchingWithOptions:] :statusBarStyle:statusBarHidden:] 21: -[UIApplication handleEvent:withNewEvent:] で 0x2d7db2 22: -[UIApplication sendEvent:] で 0x2d0202 23: _UIApplicationHandleEvent で 0x2d5732 24: PurpleEventCallback で 0x18eca36 25: 0xf98064 でオプション:] 15: -[UIViewController _loadViewFromNibNamed:bundle:] の 0x37aa94 16: -[UIViewController loadView] の 0x378709 17: -[UIViewController ビュー] の 0x3785e3 18: -[PesquisaMapaAppDelegate アプリケーション:didFinishLaunchingWithOptions:] の 0x22fe /Users/pcasqueiro /Documents/PesquisaMapa/Classes/PesquisaMapaAppDelegate.m:24 19: 0x2cb1fa in -[UIApplication _callInitializationDelegatesForURL:payload:suspended:] 20: 0x2cd55e in -[UIApplication _runWithURL:payload:launchOrientation:statusBarStyle:statusBarHidden:] 21: 0x2d7db2 in -[ UIApplication handleEvent:withNewEvent:] 22: -[UIApplication sendEvent:] で 0x2d0202 23: _UIApplicationHandleEvent で 0x2d5732 24: PurpleEventCallback で 0x18eca36 25: 0xf98064 でオプション:] 15: -[UIViewController _loadViewFromNibNamed:bundle:] の 0x37aa94 16: -[UIViewController loadView] の 0x378709 17: -[UIViewController ビュー] の 0x3785e3 18: -[PesquisaMapaAppDelegate アプリケーション:didFinishLaunchingWithOptions:] の 0x22fe /Users/pcasqueiro /Documents/PesquisaMapa/Classes/PesquisaMapaAppDelegate.m:24 19: 0x2cb1fa in -[UIApplication _callInitializationDelegatesForURL:payload:suspended:] 20: 0x2cd55e in -[UIApplication _runWithURL:payload:launchOrientation:statusBarStyle:statusBarHidden:] 21: 0x2d7db2 in -[ UIApplication handleEvent:withNewEvent:] 22: -[UIApplication sendEvent:] で 0x2d0202 23: _UIApplicationHandleEvent で 0x2d5732 24: PurpleEventCallback で 0x18eca36 25: 0xf98064 で-[UIViewController loadView] で 0x378709 17: -[UIViewController ビュー] で 0x3785e3 18: -[PesquisaMapaAppDelegate アプリケーション:didFinishLaunchingWithOptions:] で 0x22fe /Users/pcasqueiro/Documents/PesquisaMapa/Classes/PesquisaMapaAppDelegate.m:24 で 19: 0x2cb1fa - [UIApplication _callInitializationDelegatesForURL:payload:suspended:] 20: 0x2cd55e in -[UIApplication _runWithURL:payload:launchOrientation:statusBarStyle:statusBarHidden:] 21: 0x2d7db2 in -[UIApplication handleEvent:withNewEvent:] 22: 0x2d0202 in -[UIApplication sendEvent:] 23 : _UIApplicationHandleEvent の 0x2d5732 24: PurpleEventCallback の 0x18eca36 25: 0xf98064 の-[UIViewController loadView] で 0x378709 17: -[UIViewController ビュー] で 0x3785e3 18: -[PesquisaMapaAppDelegate アプリケーション:didFinishLaunchingWithOptions:] で 0x22fe /Users/pcasqueiro/Documents/PesquisaMapa/Classes/PesquisaMapaAppDelegate.m:24 で 19: 0x2cb1fa - [UIApplication _callInitializationDelegatesForURL:payload:suspended:] 20: 0x2cd55e in -[UIApplication _runWithURL:payload:launchOrientation:statusBarStyle:statusBarHidden:] 21: 0x2d7db2 in -[UIApplication handleEvent:withNewEvent:] 22: 0x2d0202 in -[UIApplication sendEvent:] 23 : _UIApplicationHandleEvent の 0x2d5732 24: PurpleEventCallback の 0x18eca36 25: 0xf98064 の] /Users/pcasqueiro/Documents/PesquisaMapa/Classes/PesquisaMapaAppDelegate.m:24 で 19: 0x2cb1fa in -[UIApplication _callInitializationDelegatesForURL:payload:suspended:] 20: 0x2cd55e in -[UIApplication _runWithURL:payload:launchOrientation:statusBarStyle:statusBarHidden:] 21: -[UIApplication handleEvent:withNewEvent:] で 0x2d7db2 22: -[UIApplication sendEvent:] で 0x2d0202 23: _UIApplicationHandleEvent で 0x2d5732 24: PurpleEventCallback で 0x18eca36 25: 0xf98064 で] /Users/pcasqueiro/Documents/PesquisaMapa/Classes/PesquisaMapaAppDelegate.m:24 で 19: 0x2cb1fa in -[UIApplication _callInitializationDelegatesForURL:payload:suspended:] 20: 0x2cd55e in -[UIApplication _runWithURL:payload:launchOrientation:statusBarStyle:statusBarHidden:] 21: -[UIApplication handleEvent:withNewEvent:] で 0x2d7db2 22: -[UIApplication sendEvent:] で 0x2d0202 23: _UIApplicationHandleEvent で 0x2d5732 24: PurpleEventCallback で 0x18eca36 25: 0xf98064 で_UIApplicationHandleEvent 24 の 0x2d5732: PurpleEventCallback 25 の 0x18eca36: 0xf98064_UIApplicationHandleEvent 24 の 0x2d5732: PurpleEventCallback 25 の 0x18eca36: 0xf98064CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE1_PERFORM_FUNCTION 26: 0xef86f7 in __CFRunLoopDoSource1 27: 0xef5983 in __CFRunLoopRun 28: 0xef5240 in CFRunLoopRunSpecific 29: 0xef5161 in CFRunLoopRunInMode 30: 0x2ccfa8 in -[UIApplication _run] 31: 0x2d942e in UIApplicationMain 32: 0x228c in main at /Users/pcasqueiro/Documents/PesquisaMapa/ main.m:14 33: 0x221d 開始

メインクラスの didFinishLaunchingWithOptions でクリーンアップが行われているようです。

私が間違っていることについてのアイデアはありますか?

ありがとう、パソコン

4

1 に答える 1

0

UITableView (および他のほとんどのクラス) はデリゲートを保持しません。つまり、なんらかの方法でデリゲートを保持しない場合 (たとえば、retain と宣言されたプロパティにデリゲートを割り当てるなど) は、メインの実行ループによってある時点で破棄されます。

于 2011-02-27T01:06:35.240 に答える