UITableView行 - 取消选择并更改突出显示:NO选择另一行

时间:2015-01-21 01:42:59

标签: ios objective-c uitableview

我只是在学习所有这些东西,请原谅我,如果我犯了一个明显的错误。

我有一系列专业知识:@ [@“NOVICE”,@“INTERMEDIATE”,@“PRO”,@“ALL LEVELS”]。

用户最多可以选择两个,但如果选择了ALL LEVELS,则执行segue并保存设置。

我想避免的是用户选择NOVICE和PRO。如果选择了NOVICE,我希望PRO被取消选择并且不会突出显示。反之亦然。

这就是我所拥有的,但我收到了错误:

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
NSString *organizeLevelOfPlay = self.organizeDifficultyArray[indexPath.row];

 if ([organizeLevelOfPlay isEqualToString:@"ALL LEVELS"]){
    [self performSegueWithIdentifier:@"MinimumNumberOfPlayers" sender:self];

} else if ([organizeLevelOfPlay isEqualToString:@"NOVICE"]){
    [self.organizeDifficultyArray[2] setHighlighted:NO animated:YES]; //I get an error here.
    [self.selectionArray removeObject:self.organizeDifficultyArray[2]];
    [self.selectionArray addObject:organizeLevelOfPlay];
    self.result = [[self.selectionArray valueForKey:@"description"] componentsJoinedByString:@"/"];
    NSLog(@"%@", self.selectionArray);

} else if ([organizeLevelOfPlay isEqualToString:@"INTERMEDIATE"]) {
    [self.selectionArray addObject:organizeLevelOfPlay];
    self.result = [[self.selectionArray valueForKey:@"description"] componentsJoinedByString:@"/"];
    NSLog(@"%@", self.selectionArray);

} else if ([organizeLevelOfPlay isEqualToString:@"PRO"]){
    [self.organizeDifficultyArray[0] setHighlighted:NO animated:YES]; //I get an error here.
    [self.selectionArray removeObject:self.organizeDifficultyArray[0]];
    [self.selectionArray addObject:organizeLevelOfPlay];
    self.result = [[self.selectionArray valueForKey:@"description"] componentsJoinedByString:@"/"];
    NSLog(@"%@", self.selectionArray);
}}

1 个答案:

答案 0 :(得分:0)

尝试使用 -[tableView: deselectRowAtIndexPath:]函数替换-[setHighlighted:NO animated:YES]@"NOVICE"@"PRO"可能是indexpath{0,1}indexpath{0,2}