プロジェクトのビュー コントローラーで UITableView のセルを選択すると、ランダムにクラッシュします。
問題は、再利用しようとしているセルが原因だと思います。
これがコードです。
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
[self reinitializeStrArray];
static NSString *CellIdentifier = @"cell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {
cell = [[[UITableViewCell alloc]
initWithStyle:UITableViewCellStyleDefault
reuseIdentifier:CellIdentifier] autorelease];
}
cell.textLabel.text = [strArray objectAtIndex:indexPath.row];
return cell;
}
- (void)addStrTableToSubView{
strTable = [[UITableView alloc] initWithFrame:CGRectMake(20, 110, 280, 285)];
[strTable setDelegate:self];
[strTable setDataSource:self];
[self.view addSubview:strTable];
UILabel *label = [[[UILabel alloc] initWithFrame:CGRectMake(20, 83, 280, 28)] autorelease];
UIColor *myColor = [UIColor colorWithRed:(215 / 255.0) green:(145 / 255.0) blue:(0.0 / 255.0) alpha: 1];
label.backgroundColor = myColor;
label.font = [UIFont boldSystemFontOfSize:24];
label.shadowColor = [UIColor colorWithWhite:0.0 alpha:0.8];
label.textAlignment = UITextAlignmentCenter;
label.textColor = [UIColor whiteColor];
label.text = [@"strings" capitalizedString];
[self.view addSubview:label];
[strTable selectRowAtIndexPath:scrollStrIndexPath animated:YES scrollPosition:UITableViewScrollPositionTop];
}
XCode でテーブルを作成します。そのため、IB には識別子を持つ UITableViewCell オブジェクトはありません。
テーブルの作成中にこれをコードに追加することは可能ですか? それとも別の場所に問題がありますか?
ありがとう