有這個控件,我真的很感謝:github link問題是,現在我有一種情況,當我需要打開一行,所有以前的應該關閉,我只能有一個打開的行當時。UITableView控件上的不同行爲
因爲我對xcode不是很有經驗,所以我需要一些信息來說明我應該從哪裏開始以及使代碼按照我現在需要的方式工作的必要步驟。
我設法做一些測試,但不是一個可行的解決方案,這裏是我現在所擁有的:提前
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
[tableView deselectRowAtIndexPath:indexPath animated:YES];
NSInteger row = indexPath.row;
if (indexPath.section == 0) {
NSLog(@"indexPath1 = %i", selectedRow);
NSDictionary *d = [self.firstForTable objectAtIndex:indexPath.row];
if([d valueForKey:@"Objects"]) {
NSArray *ar = [d valueForKey:@"Objects"];
NSUInteger count = indexPath.row +1;
NSMutableArray *arCells = [NSMutableArray array];
for(NSDictionary *dInner in ar) {
[arCells addObject:[NSIndexPath indexPathForRow:count inSection:0]];
[self.firstForTable insertObject:dInner atIndex:count++];
}
[tableView insertRowsAtIndexPaths:arCells withRowAnimation:UITableViewRowAnimationLeft];
}
else {
NSLog(@"Leave Element:::%@ %@|",[d valueForKey:@"name"],[d valueForKey:@"book"]);
}
if (selectedRow == row) {
NSLog(@"selectedRow2 = %i",selectedRow);
NSDictionary *d=[self.firstForTable objectAtIndex:selectedRow];
if([d valueForKey:@"Objects"]) {
NSArray *ar = [d valueForKey:@"Objects"];
[self miniMizeFirstsRows:ar];
}
selectedRow = -1;
return;
}
if (selectedRow >= 0) {
NSLog(@"selectedRow3 = %i",selectedRow);
NSDictionary *d=[self.firstForTable objectAtIndex:selectedRow];
if([d valueForKey:@"Objects"]) {
NSArray *ar = [d valueForKey:@"Objects"];
[self miniMizeFirstsRows:ar];
}
selectedRow = row;
}
selectedRow = row;
[tableView beginUpdates]; [tableView endUpdates];
}
if (indexPath.section == 1) {
NSDictionary *d = [self.secondForTable objectAtIndex:indexPath.row];
if([d valueForKey:@"Objects"]) {
NSArray *ar = [d valueForKey:@"Objects"];
BOOL isAlreadyInserted=NO;
for (NSDictionary *dInner in ar) {
NSInteger index = [self.secondForTable indexOfObjectIdenticalTo:dInner];
isAlreadyInserted = (index > 0 && index != NSIntegerMax);
if (isAlreadyInserted) break;
}
if (isAlreadyInserted) {
[self miniMizeSecondsRows:ar];
}
else {
NSUInteger count = indexPath.row+1;
NSMutableArray *arCells = [NSMutableArray array];
for (NSDictionary *dInner in ar) {
[arCells addObject:[NSIndexPath indexPathForRow:count inSection:1]];
[self.secondForTable insertObject:dInner atIndex:count++];
}
[tableView insertRowsAtIndexPaths:arCells withRowAnimation:UITableViewRowAnimationLeft];
}
}
else {
NSLog(@"Leave Element:::%@ %@|",[d valueForKey:@"name"],[d valueForKey:@"book"]);
}
}
}
感謝。
你需要什麼方式?目前還不清楚你的目標是什麼...... – Beppe
在當前的github控件中,你可以自由地打開有許多你喜歡的行,並且它們將保持打開狀態,我需要的是限制tableview打開只有一行時間。如果我打開一行,其他可能打開的行必須自動關閉:) – Bruno
'[tableView deselectRowAtIndexPath:indexPath animated:YES];'你是否使用這條線來取消選擇之前打開的行?如果不是它在哪裏? – JJ86