У меня есть изменяемый массив (отредактированСервисные части) с двумя объектами в нем; У меня есть табличный вид, содержащий около 30 ячеек. Я хочу проверить, отображаются ли какие-либо ячейки таблицы (cell.textLabel.text) в изменяемом массиве; если они это сделают, я хочу установить cell.accessory в галочку.Проверка ошибки логической схемы быстрого сравнения для сравнения UITableViewCell
ОБНОВЛЕНО Это мой код из -cellForRowAtIndexPath:
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
// get the timeFormat
NSUserDefaults *userDefaults = [NSUserDefaults standardUserDefaults];
NSMutableDictionary *preferencesDict = [[userDefaults dictionaryForKey:@"preferencesDictionary"] mutableCopy];
int iTimeFormat = [[preferencesDict objectForKey:@"timeFormat"] intValue]; // set timeFormat
NSMutableArray *selectedServicesParts = [NSMutableArray new];
NSMutableArray *editedServiceParts = [NSMutableArray new];
NSString *service;
if(tableView.tag == kServicesTableView) { // services array
static NSString *CellIdentifier = @"apptServicesCell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {
cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier];
}
// Configure the cell
SingletonServicesArray *sharedServicesArray = [SingletonServicesArray sharedServicesArray]; // list of available services
[cell.textLabel setText:[sharedServicesArray.globalServicesArray objectAtIndex:indexPath.row]]; // move selected row to cell
// separate soServices.text into individual elements
NSString *cleanService;
if(soServices.text.length > 0) {
selectedServicesParts = [[soServices.text componentsSeparatedByString:@","] mutableCopy];
for(int x = 0; x < selectedServicesParts.count; x++) {
cleanService = [selectedServicesParts[x] stringByReplacingOccurrencesOfString:@"," withString:@""];
[editedServiceParts insertObject: cleanService atIndex: x];
}
}
// now, take the editedServicesParts (w/o commas) and mark cell if appropriate
for (int i = 0; i < editedServiceParts.count; i++) { if ([editedServiceParts containsObject:cell.textLabel.text]) {
cell.accessoryType = UITableViewCellAccessoryCheckmark;
} else {
// Remove accessory mark of recycled cells
cell.accessoryType = UITableViewCellAccessoryNone;
}
}
// for (int i = 0; i < editedServiceParts.count; i++) { // total number of rows in list of all available services
//
// for(service in editedServiceParts) {
// if([cell.textLabel.text isEqualToString: service]) {
// cell.accessoryType = UITableViewCellAccessoryCheckmark;
// break;
}
// }
// }
return cell;
}
То, что происходит это только первое сравнение был найден, хотя есть другой, который должен был быть найден. Я боюсь, что у меня есть логическая проблема, и для меня жизнь я не вижу. Помощь будет принята с благодарностью!
SD
Зачем вам нужен внешний контур, который повторяет ту же задачу несколько раз? – dasblinkenlight
И ваши внутренние, и внешние петли повторяются над отредактированными параметрами. Вы хотели бы, чтобы внутренний цикл повторялся по ячейкам просмотра таблицы? – DanielG
'cell' никогда не изменяется, поэтому вы постоянно проверяете один и тот же текст ячейки. –