0
我只是在學習所有這些東西,所以如果我犯了一個明顯的錯誤,請原諒。UITableView行 - 通過選擇另一行取消選擇和更改高亮:否
我有一系列專業知識水平:@ [@「NOVICE」,@「INTERMEDIATE」,@「PRO」,@「所有水平」];
用戶最多可以選擇兩個,但是如果選擇了所有等級,則執行繼續並保存設置。
我想避免的是用戶選擇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);
}}
我想你的意思是'deselectRowAtIndexPath:' – Paulw11 2015-01-21 02:01:37
謝謝你的回答。我很感激。但是,我的問題並不完全取消選擇該行。我能用removeObject做到這一點。但是在取消選擇/刪除後,該行保持高亮顯示。選擇後者時,我需要基本不重視前一行。反之亦然。再次感謝! – michelh 2015-01-21 02:42:38
你可以在tableview委託中測試 - [tableView:willDisplayCell:forRowAtIndexPath:]方法。如果您不想強調該方法,只需使用該方法,在該單元格中將[setSelected:animated:]設置爲No。 – 2015-01-21 02:54:44