0

カスタマイズされたセルのリストを表示するTableView(クラスListeExercice)を実装しています。これらのセルは別のクラス(クラスExerciceTableCell)で定義されています。

ListeExerciceクラスでは、viewDidLoadメソッドで次のようにNSArrayを作成します。

table1 = [NSArray arrayWithObjects:@"exo1", @"exo2", nil];
table2 = [NSArray arrayWithObjects:@"10:00", @"10:00", nil];

次に、同じクラスで、テーブル内のセルを表示するためにすべてを実行します

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
- (NSString *)tableView:(UITableView *)tableView titleForHeaderInSection(NSInteger)section
- (NSArray *)sectionIndexTitlesForTableView:(UITableView *)tableView

私が得た問題は、基本的に正しいセルを表示するためのコードが配置されている次のメソッドで発生します。

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {

static NSString *exerciceTableIdentifier = @"ExerciceTableCell";
ExerciceTableCell *cell = (ExerciceTableCell *)[tableView dequeueReusableCellWithIdentifier:exerciceTableIdentifier];
if (cell == nil) 
{
    NSArray *nib = [[NSBundle mainBundle] loadNibNamed:@"ExerciceTableCell" owner:self options:nil];
    cell = [nib objectAtIndex:0];
} 

//label1 is a label from the cell defined in the ExerciceTableCell class.

cell.label1.text = [tableIntituleExercice objectAtIndex:indexPath.row];

return cell;

}

問題は、これら2つの行の間に競合が発生したことです。

cell = [nib objectAtIndex:0];

cell.Label1.text = [table1 objectAtIndex:indexPath.row];

どうやら、2つの「objectAtIndex」の間に競合があります。警告はなく、アプリがクラッシュするだけで、「スレッド1:EXC_BAD_ACCESS(code = 1 ....)」というスレッドが表示されます。

私に何ができるかについて何かアドバイスはありますか?

4

1 に答える 1

1

ARCを使用していない場合は、単純なメモリ管理エラーです。次の行に2つの配列を保持する必要があります。

table1 = [NSArray arrayWithObjects:@"exo1", @"exo2", nil];
table2 = [NSArray arrayWithObjects:@"10:00", @"10:00", nil];

それ以外の場合、オブジェクトはtableView:cellForRowAtIndexPath:呼び出される前に解放されます。このようなエラーの場合、通常は常にプロパティセッターを使用してivars/propertiesに値を割り当てる必要があります。セッターはあなたのために適切なメモリ管理を気にします。

于 2012-06-07T08:55:22.163 に答える