ここでは奇妙なことがあります。私は、プロトコルから必要なすべてのメソッドとそれで使用するデータを持つ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
ダミーデータと同じ動作をします。
tableViewDataは何ですか?それはあなたが作成した配列ですか?もしそうなら、それをどのようにインスタンス化していますか? – sosborn
tableViewDataのプロパティ宣言、initコード、およびクリーンアップコードを表示できますか? – bryanmac
'tableViewData'とは何ですか? 'viewDidLoad'でコードを提供してください。ありがとう。 –