내 앱의 셀이 NSUserDefaults에 저장된 NSMutableArray의 단어와 제목이 일치하는 행에만 체크 표시를 표시하려고합니다. 지금 당장 내 문제는 모든 앱에 체크 표시가되어 있다는 것입니다. 심지어 행이 아무 것도 일치하지 않는 경우에도 마찬가지입니다. 다음은 내 코드와 콘솔 로그입니다.iOS UITableView CheckMark가 모든 행에 표시됩니다.
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
static NSString *CellIdentifier = @"Cell";
Cell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {
cell = [[Cell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:CellIdentifier];
}
NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
RSSEntry *entry = [_allEntries objectAtIndex:indexPath.row];
NSArray *rowsarray = [defaults objectForKey:@"checkedrows"];
NSLog(@"ORIGINAL%@", rowsarray);
NSPredicate *predicate = [NSPredicate predicateWithFormat: @"SELF contains[cd] %@", entry.date];
NSArray *filteredArray = [rowsarray filteredArrayUsingPredicate: predicate];
NSString *myString = [filteredArray componentsJoinedByString:@""];
NSLog(@"The array %@", filteredArray);
NSLog(@"The string %@", myString);
if([entry.date isEqualToString:myString]) {
cell.accessoryType = UITableViewCellAccessoryCheckmark;
}
UIFont *cellFont = [UIFont fontWithName:@"Papyrus" size:19];
UIFont *cellFont2 = [UIFont fontWithName:@"Papyrus" size:17];
cell.textLabel.text = entry.date;
cell.detailTextLabel.text = entry.articleTitle;
cell.detailTextLabel.textColor = [UIColor blackColor];
cell.textLabel.font = cellFont;
cell.detailTextLabel.font = cellFont2;
return cell;
}
콘솔 로그 : 당신이 볼 수 있듯이, 반환되는 유일한 문자열은 1 일 :.
2012-12-20 11:02:53.793 5MWG[3615:c07] ORIGINAL(
"Day 1: "
)
2012-12-20 11:02:53.794 5MWG[3615:c07] The array (
"Day 1: "
)
2012-12-20 11:02:53.794 5MWG[3615:c07] The string Day 1:
2012-12-20 11:06:23.851 5MWG[3615:c07] 2
2012-12-20 11:06:23.852 5MWG[3615:c07] ORIGINAL(
"Day 1: "
)
2012-12-20 11:06:23.852 5MWG[3615:c07] The array (
)
2012-12-20 11:06:23.852 5MWG[3615:c07] The string
2012-12-20 11:06:23.854 5MWG[3615:c07] 2
2012-12-20 11:06:23.854 5MWG[3615:c07] ORIGINAL(
"Day 1: "
)
2012-12-20 11:06:23.855 5MWG[3615:c07] The array (
"Day 1: "
)
2012-12-20 11:06:23.855 5MWG[3615:c07] The string Day 1:
입니다 그러나 entry.date = Day 2 : 인 행조차도 체크 표시가 표시됩니다. 다음과 같이 조건부로 if
을
if([entry.date isEqualToString:myString]) {
cell.accessoryType = UITableViewCellAccessoryCheckmark;
} else {
cell.accessoryType = UITableViewCellAccessoryNone;
}