2012-02-06 18 views
1

ここでは奇妙なことがあります。私は、プロトコルから必要なすべてのメソッドとそれで使用するデータを持つUITableViewControllerを持っています。それから私は、このコード(簡体字)起動アプリケーションでEXC_BAD_ACCESSエラーが発生しました

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{ 
static NSString *CellIdentifier = @"Cell"; 

UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier]; 
if (cell == nil) { 
    cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier] autorelease]; 
} 

NSDictionary* cellData = [self.tableViewData objectAtIndex:indexPath.row]; 
// the rest of the code 

return cell; 
} 

このTableViewControllerは、それがAppDelegateに呼び出されたり参照されていないので、数回のクリック後に実行されなければならないか、どこかのViewControllerで最初に読み込まれることがあります。 しかし、(正常に)ビルドしてシミュレータでアプリケーションを実行すると、何かが表示される前にEXC_BAD_ACCESSエラーで終了します。私はラインをコメントするときそれを考え出しました:

NSDictionary* cellData = [self.tableViewData objectAtIndex:indexPath.row]; 

すべて正常に動作しています。どのようにこれに何があるのでしょうか? また、tableViewDataはviewDidLoadにロードされ、この行の前に解放されず、それ以外はokです(これより下の行も削除できます)。とにかくこのエラーを送信すべきではありませんが、アプリケーションの起動時に行われます。何がありますか? EDIT

:これは私がのtableViewに経口tableViewDataから得るものです :cellForRowAtIndexPath:

- (void)viewDidUnload { 
[super viewDidUnload]; 
self.tableViewData = nil; 
} 

-(void)dealloc{ 
[tableViewData release]; 
[super dealloc]; 
} 

EDIT:コードの

- (void)viewDidLoad { 
[super viewDidLoad]; 

self.tableViewData = [self getABContactsWithMail]; //gets filtered contacts from addressbook, works fine 
} 
ここ

ある他の部分:ここで はviewDidLoadメソッドである

<__NSArrayM 0xfdcfe30>(
{ 
email = "[email protected]"; 
firstName = test; 
fullName = "test account"; 
id = 1; 
lastName = account; 
phone = "1 (231) 23"; 
}, 
{ 
email = "[email protected]"; 
firstName = nolast; 
fullName = nolast; 
id = 3; 
lastName = ""; 
phone = ""; 
}, 
{ 
email = "[email protected]"; 
firstName = ""; 
fullName = nofirst; 
id = 4; 
lastName = nofirst; 
phone = ""; 
}, 
{ 
email = "[email protected]"; 
firstName = ""; 
fullName = "[email protected]"; 
id = 5; 
lastName = ""; 
phone = ""; 
} 
) 

EDIT: メソッドを追加しました:

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath 

ダミーデータと同じ動作をします。

+0

tableViewDataは何ですか?それはあなたが作成した配列ですか?もしそうなら、それをどのようにインスタンス化していますか? – sosborn

+0

tableViewDataのプロパティ宣言、initコード、およびクリーンアップコードを表示できますか? – bryanmac

+0

'tableViewData'とは何ですか? 'viewDidLoad'でコードを提供してください。ありがとう。 –

答えて

0

私はようやく試行錯誤でそれを見つけました。どうやら私のUITableViewControllerは、親クラスに既に実装されているプロトコルのいくつかを実装しています。そして、それは全体の問題でした...

私は本当になぜ無関係なエラーで無関係な場所にアプリケーションが壊れたのかわかりません。これが私のコーディングミスであれば、コンパイラは少なくとも私に警告しなければなりません。

また、私は、私はアップルにバグとしてこれを提出

...私はXcodeの3で問題なくこれをやっていたことを覚えておいてください...

0

はあなたが私たちに提供することができます...何かが台無しにされるのUITableViewController自身や私のXcodeと間違っているようだ、あなたの方法 - (NSInteger)のtableView:(のUITableView *)のtableView numberOfRowsInSection:(NSInteger)セクション

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section { 
    return [tableViewData count]; 
} 
+0

あなたの言葉通りです。セクション数も1にする必要があります – adnanced

関連する問題