いくつかのカスタムセルを持つ UITableView があり、そのうちの 2 つにはイメージビューが含まれています。それらに画像が取り込まれているときは問題ありませんが、テーブルビューを下にスクロールして画像ビューが表示されないようにすると、画像が消えて空白になります。
CellForRowAtIndexPath Method
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
static NSString *CellIdentifier = @"Cell";
static NSString *GECIdentifier = @"GECell";
static NSString *TECIdentifier = @"TECell";
static NSString *AMCIdentifier = @"AMCell";
if (indexPath.section == 0) {
//Create generic GEC for use by all rows in section
GeneralEditingCell *GEC = [self.tableView dequeueReusableCellWithIdentifier:GECIdentifier];
if (GEC == nil) {
GEC = [[GeneralEditingCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier];
GEC.accessoryType = UITableViewCellAccessoryNone;
GEC.selectionStyle = UITableViewCellSelectionStyleNone;
GEC.master = self;
}
//Create and setup datepicker and dateformatter for later use
UIDatePicker *datePicker = [[UIDatePicker alloc]init];
datePicker.datePickerMode = UIDatePickerModeDate;
datePicker.tag = indexPath.row;
[datePicker addTarget:self action:@selector(pickerChanged:) forControlEvents:UIControlEventValueChanged];
NSDateFormatter *formatter = [[NSDateFormatter alloc]init];
[formatter setDateFormat:@"LLL dd, yyyy"];
//Configure each cell individually
switch (indexPath.row) {
case 0:
if (editing) {
GEC.titleField.text = [item objectForKey:@"Title"];
GEC.dateField.text = [item objectForKey:@"Date"];
GEC.imageView.image = [self getThumbnailforVideoAtPath:[NSURL fileURLWithPath:[item objectForKey:@"Video Path"]]];
} else {
GEC.dateField.text = [formatter stringFromDate:[NSDate date]];
GEC.dateField.inputView = datePicker;
}
break;
default:
break;
}
return GEC;
}
if (indexPath.section == 1) {
//Create generic TEC for use by all rows in section
TextEditingCell *TEC = [self.tableView dequeueReusableCellWithIdentifier:TECIdentifier];
if (TEC == nil) {
TEC = [[TextEditingCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier];
TEC.accessoryType = UITableViewCellAccessoryNone;
TEC.selectionStyle = UITableViewCellSelectionStyleNone;
}
//Configure each cell individually
switch (indexPath.section) {
case 0:
if (editing) {
TEC.textField.text = @"Editing Mode";
} else {
TEC.label.text = @"TextEdit Cell";
}
break;
default:
break;
}
return TEC;
}
if (indexPath.section == 2) {
//Create generic AMC for use by all rows in section
AddMediaCell *AMC = [self.tableView dequeueReusableCellWithIdentifier:AMCIdentifier];
if (AMC == nil) {
AMC = [[AddMediaCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier];
AMC.accessoryType = UITableViewCellAccessoryNone;
AMC.selectionStyle = UITableViewCellSelectionStyleNone;
}
//Configure each cell individually
switch (indexPath.row) {
case 0:
AMC.label.text = @"Add Video";
break;
case 1:
AMC.label.text = @"Add Photos";
break;
case 2:
AMC.label.text = @"Record Audio";
break;
case 3:
AMC.label.text = @"Add Text Note";
break;
case 4:
AMC.label.text = @"Attach Location";
break;
case 5:
AMC.label.text = @"Attach Weather Data";
break;
case 6:
AMC.label.text = @"Add More Tags";
break;
default:
break;
}
return AMC;
}
//Catch any previously unhandled cell
UITableViewCell *errorCell = [self.tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (errorCell == nil) {
errorCell = [[UITableViewCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier];
}
errorCell.textLabel.text = @"ERROR! UNHANDLED CELL!!!";
return errorCell;
}