2012-12-19 2 views
0

내 앱의 셀이 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; 
} 

답변

2

당신은 else을 추가해야하거나, 다시 쓰기 : 그렇지 않으면

cell.accessoryType = [entry.date isEqualToString:myString] 
? UITableViewCellAccessoryCheckmark 
: UITableViewCellAccessoryNone; 

, 셀을 수표로

1

당신은 작성해야 마크 세트는 "재활용"될 때 액세서리를 영원히 유지합니다. 이

if([entry.date isEqualToString:myString]) { 
    cell.accessoryType = UITableViewCellAccessoryCheckmark; 

}else 
{ 
    cell.accessoryType = UITableViewCellAccessoryNone; 
} 
0

당신은 재사용 식별자 큐에서 당신은 다음, 한 모든 재활용 셀을 없음으로 cell.accessoryType를 설정하지 않는 경우 과거의 수표에는 장래에 수표가 발행됩니다.

3

내가 코드에 너무 밀접하게 보지 않았다 도움이되지만한다

관련 문제