У меня есть Пользователь UITableViewCell
с UIImage
и UILabel
(см. Снимок экрана ниже). Изображение в пользовательских UITableViewCell перемещается после выбора
Если я нажимаю на UITableViewCell
я добавить Checkmark к нему, но когда галочка видна на UIImage
перемещается влево (см рисунок ниже).
Автоотключение отключено, а для режима содержимого установлено значение UIViewContentModeRight
(через раскадровку).
Мой код:
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
MarkerCell *cell = (MarkerCell *)[tableView dequeueReusableCellWithIdentifier:@"marker"];
markerCategories = [[NSMutableArray alloc] init];
for (Marker *marker in self.allMarkers) {
BOOL isEqual = NO;
for (NSString *string in markerCategories) {
if ([marker.identifier isEqualToString:string]) {
isEqual = YES;
}
}
if (isEqual == NO) {
[markerCategories addObject:marker.identifier];
}
}
cell.backgroundColor = [UIColor clearColor];
cell.opaque = NO;
cell.backgroundView = nil;
cell.lbMarkerName.text = markerCategories[indexPath.row];
cell.ivIcon.image = [UIImage imageNamed:[markerCategories[indexPath.row] lowercaseString]];
if ([markerCategories[indexPath.row] isEqualToString:@"Löschteich"]) cell.ivIcon.image = [UIImage imageNamed:@"loeschteich"];
if (!cell.ivIcon.image) cell.ivIcon.image = [UIImage imageNamed:@"sonstige"];
return cell;
}
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
MarkerCell *cell = (MarkerCell *)[tableView cellForRowAtIndexPath:indexPath];
// handle Checkmark
if (cell.accessoryType == UITableViewCellAccessoryCheckmark) {
[cell setAccessoryType:UITableViewCellAccessoryNone];
// remove Marker(s)
for (Marker *marker in self.allMarkers) {
if ([markerCategories[indexPath.row] isEqualToString:marker.identifier]) {
[markersToShow removeObject:marker];
}
}
}
else
{
[cell setAccessoryType:UITableViewCellAccessoryCheckmark];
// add Marker(s)
for (Marker *marker in self.allMarkers) {
if ([markerCategories[indexPath.row] isEqualToString:marker.identifier]) {
[markersToShow addObject:marker];
}
}
}
[tableView deselectRowAtIndexPath:indexPath animated:YES];
[self printMarkers];
}