0

の行はLevel 1展開して折りたたむ必要があります。Row 0が開いている場合、つまりステータスが1であり、次の行のステータスが0である場合、ステータスが である次の行をクリックすると、ステータスが 0である行が1閉じられるはずです。

どうやってやるの?

これが私のコードです:

- (void)viewDidLoad {
    [super viewDidLoad];
    dictBtnStatus = [[NSMutableDictionary alloc] init];
    arraylist = [[NSMutableArray alloc] init];
    array5 = [[NSMutableArray alloc] init];
    array1 = [[NSMutableArray alloc] init];
    objects = @[@"Medical Services In Chicago", @"Medical Services On Campus", @"ABC", @"California"];
    // objects = @[@"Medical Services In Chicago", @"Medical Services On Campus"];
    arrObjectValueChicago = @[@"Ronald McDonald® Children's Hospital of Loyola", @"Burn Centers", @"Gottlieb Hospitals"];
    arrObjectValueCampus = @[@"Cardinal Bernardin Cancer Center1", @"Center for Heart & Vascular Medicine2", @"ABC"];
    for (int i = 0; i < [arrObjectValueCampus count]; i++) {
        dictListCampus1 = [[NSDictionary alloc] initWithObjectsAndKeys:@"2", @"level",[arrObjectValueCampus objectAtIndex:i], @"name", nil];
        [array5 addObject:dictListCampus1];
    }
    NSDictionary *dictListCampus = [[NSDictionary alloc] initWithObjectsAndKeys:@"Wellness Centers", @"name", @"1", @"level", array5, @"Objects", nil];
    NSMutableArray *array6 = [[NSMutableArray alloc] initWithObjects:dictListCampus, nil];
    array3 = [[NSMutableArray alloc] init ];
    for (int i = 0; i < [arrObjectValueChicago count]; i++){
        dictList3 = [[NSDictionary alloc]initWithObjectsAndKeys:@"2", @"level",[arrObjectValueChicago objectAtIndex:i], @"name", nil];
        [array3 addObject:dictList3];
    }

    NSDictionary *dictList2 = [[NSDictionary alloc] initWithObjectsAndKeys:@"Hospitals", @"name", @"1", @"level", array3, @"Objects", nil];
    NSMutableArray *array2 = [[NSMutableArray alloc] initWithObjects:dictList2, nil];
    for (int i = 0; i < [objects count]; i++) {
        if (i == 0) {
            dictionary = [[NSDictionary alloc] initWithObjectsAndKeys:[objects objectAtIndex:0], @"name", @"0", @"level", array2, @"Objects", nil];
            [array1 addObject:dictionary];
        } else if (i == 1) {
            dictionary = [[NSDictionary alloc] initWithObjectsAndKeys:[objects objectAtIndex:1], @"name", @"0", @"level", array6, @"Objects", nil];
            [array1 addObject:dictionary];
        } else if (i == 2) {
            dictionary = [[NSDictionary alloc] initWithObjectsAndKeys:[objects objectAtIndex:2], @"name", @"0", @"level", array6, @"Objects", nil];
            [array1 addObject:dictionary];
        } else {
            dictionary = [[NSDictionary alloc] initWithObjectsAndKeys:[objects objectAtIndex:3], @"name", @"0", @"level", array2, @"Objects", nil];
            [array1 addObject:dictionary];
        }
    }
    dictList = [[NSDictionary alloc] initWithObjectsAndKeys:array1, @"Objects", nil];
    arrayOriginal = [dictList valueForKey:@"Objects"];
    [arraylist addObjectsFromArray:arrayOriginal];
}

#pragma mark - TableView
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
    return 1;
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    return [arraylist count];
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    // static NSString *CellIdentifier = @"CustomCellIdentifier";
    NSUInteger IndentLevel = [[[arraylist objectAtIndex:indexPath.row] valueForKey:@"level"] intValue];
   UITableViewCell *cell = (UITableViewCell *)[tableView dequeueReusableCellWithIdentifier:@"Cell"];
   if (IndentLevel == 0) {
       CustomCellHeader *cell = (CustomCellHeader *)[tableView dequeueReusableCellWithIdentifier:@"CellIdentifier"];
       if (cell == nil) {
           [[NSBundle mainBundle]loadNibNamed:@"CustomCellHeader" owner:self options:nil];
           cell = self.headercell;
           self.headercell = nil;
        }
        cell.lblHeader.text = [[arraylist objectAtIndex:indexPath.row] valueForKey:@"name"];
        [cell setIndentationLevel:[[[arraylist objectAtIndex:indexPath.row] valueForKey:@"level"] intValue]];
        NSLog(@"indexFor level 0 ::%@ %d",cell.lblHeader.text,indexPath.row);
        return cell;
    } else if (IndentLevel == 1) {
        CustomCellSubHeader *cell = (CustomCellSubHeader *)[tableView dequeueReusableCellWithIdentifier:@"CellIdentifier"];
        if (!cell) {
            [[NSBundle mainBundle]loadNibNamed:@"CustomCellSubHeader" owner:self options:nil];
            cell = self.subheadercell;
            self.subheadercell = nil;
            NSLog(@"dicbtn %@", dictBtnStatus);
            NSString *strName = [[arraylist objectAtIndex:indexPath.row]valueForKey:@"name"];
            NSString *str = [dictBtnStatus objectForKey:strName];
            NSLog(@"indexFor level 1 ::%@ %d", strName, indexPath.row);

            if ([str isEqualToString:@"1"]) {
                [cell.btnarrow setImage:[UIImage imageNamed:@"dwn1_arow.png"] forState:UIControlStateNormal];
                [cell.imgSubHeader setImage:[UIImage imageNamed:@"tab_active.png"]];
            }
            cell.lblSubHeader.text = strName;
            cell.imgShadow.hidden = YES;
            [cell setIndentationLevel:[[[arraylist objectAtIndex:indexPath.row] valueForKey:@"level"] intValue]];
        }
        return cell;
    } else if (IndentLevel == 2) {
        CustomCell *cell = (CustomCell *)[tableView dequeueReusableCellWithIdentifier:@"CellIdentifier"];
        if (cell == nil) {
            [[NSBundle mainBundle]loadNibNamed:@"CustomCell" owner:self options:nil];
            cell = self.cells;
            self.cells = nil;
        }
        cell.txtAddress.text = [[arraylist objectAtIndex:indexPath.row] valueForKey:@"name"];
        [cell.btnCall addTarget:self action:@selector(btnCall:) forControlEvents:UIControlEventTouchUpInside];
        [cell setIndentationLevel:[[[arraylist objectAtIndex:indexPath.row] valueForKey:@"level"] intValue]];
        return cell;
    }
    return cell;
}

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
    [tblist deselectRowAtIndexPath:indexPath animated:YES];
    NSUInteger IndentLevel = [[[arraylist objectAtIndex:indexPath.row] valueForKey:@"level"] intValue];
    NSString *strName = [[arraylist objectAtIndex:indexPath.row] valueForKey:@"name"];
    CustomCellSubHeader *cell = ((CustomCellSubHeader*)[tblist cellForRowAtIndexPath:indexPath]);
    if (IndentLevel == 1) {  
        [dictBtnStatus setValue:@"0" forKey:strName];
        [cell.btnarrow setImage:[UIImage imageNamed:@"gry_arrow.png"] forState:UIControlStateNormal];
        [cell.imgSubHeader setImage:[UIImage imageNamed:@"tab_default.png"]];
    }
    NSDictionary *d = [arraylist objectAtIndex:indexPath.row];
    if ([d valueForKey:@"Objects"]) {
        NSArray *ar = [d valueForKey:@"Objects"];
        BOOL isAlreadyInserted = NO;
        for (NSDictionary *dInner in ar) {
            NSInteger index = [arraylist indexOfObjectIdenticalTo:dInner];
            isAlreadyInserted = (index > 0 && index != NSIntegerMax);
            if (IndentLevel == 1) {
                [dictBtnStatus setValue:@"0" forKey:strName];
                [cell.btnarrow setImage:[UIImage imageNamed:@"gry_arrow.png"] forState:UIControlStateNormal];
                [cell.imgSubHeader setImage:[UIImage imageNamed:@"tab_default.png"]];
            } else if (IndentLevel == 0) {
                NSString *strStatus = [dictBtnStatus objectForKey:strName];
                if ([strStatus isEqualToString:@"1"]) {
                // NSDictionary *dict = [arraylist objectAtIndex:previousRow];
                // if ([dict valueForKey:@"Objects"]) {
                    NSArray * array = [[arraylist objectAtIndex:previousRow]valueForKey:@"Objects"];
                    [self miniMizeThisRows:array];
                }
            }
            if (isAlreadyInserted) break;
        }
        if (isAlreadyInserted) {
            if ([arraylist count] - 1 && IndentLevel == 1) {
                cell.imgShadow.hidden = NO;
            }
            if (IndentLevel == 1) {
                [dictBtnStatus setValue:@"0" forKey:strName];
                [cell.btnarrow setImage:[UIImage imageNamed:@"gry_arrow.png"] forState:UIControlStateNormal];
                [cell.imgSubHeader setImage:[UIImage imageNamed:@"tab_default.png"]];
            } else if (IndentLevel == 0) {
                [dictBtnStatus setValue:@"0" forKey:strName];
            }
            [self miniMizeThisRows:ar];
        } else {
            NSUInteger count=indexPath.row + 1;
            NSMutableArray *arCells = [NSMutableArray array];
            for (NSDictionary *dInner in ar) {
                [arCells addObject:[NSIndexPath indexPathForRow:count inSection:0]];
                previousRow  = [indexPath row];
                if (IndentLevel == 1) {
                    [dictBtnStatus setValue:@"1" forKey:strName];
                    [cell.btnarrow setImage:[UIImage imageNamed:@"dwn1_arow.png"] forState:UIControlStateNormal];
                    [cell.imgSubHeader setImage:[UIImage imageNamed:@"tab_active.png"]];
                } else if (IndentLevel == 0) {
                    [dictBtnStatus setValue:@"1" forKey:strName];
                }
                [arraylist insertObject:dInner atIndex:count++];
            }
        [tableView insertRowsAtIndexPaths:arCells withRowAnimation:UITableViewRowAnimationNone];
        }
    }
}

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {
    NSUInteger indentLevel = [[[arraylist objectAtIndex:indexPath.row] valueForKey:@"level"] intValue];
    if (indentLevel == 0) {
        return 40;
    } else if (indentLevel == 1) {
        return 25;
    } else if (indentLevel == 2) {
        CustomCell *cell = ((CustomCell *)[tableView dequeueReusableCellWithIdentifier:@"CellIdentifier"]);
        CGSize maximumSize = CGSizeMake(300, 9999);
        UIFont *myFont = [UIFont fontWithName:@"Arial" size:11.5];
        CGSize myStringSize = [cell.txtAddress.text sizeWithFont:myFont constrainedToSize:maximumSize lineBreakMode:NSLineBreakByWordWrapping];
        [cell.txtAddress setFrame:CGRectMake(cell.txtAddress.frame.origin.x, cell.txtAddress.frame.origin.y, cell.txtAddress.frame.size.width, myStringSize.height)];

        if (myStringSize.height > 80) {
            myStringSize.height = 50;
            [cell.txtAddress setFrame:CGRectMake(cell.txtAddress.frame.origin.x, cell.txtAddress.frame.origin.y, cell.txtAddress.frame.size.width, myStringSize.height)];
            cell.txtAddress.scrollEnabled = YES;
        } else {
            cell.txtAddress.scrollEnabled = YES;
            myStringSize.height = 40;
        }
        return myStringSize.height+ 50;
    } else return 25;
}

#pragma mark - TableAnimation

- (void)miniMizeThisRows:(NSArray *)ar {
    for(NSDictionary *dInner in ar) {
        NSUInteger indexToRemove = [arraylist indexOfObjectIdenticalTo:dInner];
        NSArray *arInner = [dInner valueForKey:@"Objects"];
        if (arInner && [arInner count] > 0) {
            [self miniMizeThisRows:arInner];
        }      
        if ([arraylist indexOfObjectIdenticalTo:dInner]!= NSNotFound) {
            [arraylist removeObjectIdenticalTo:dInner];
            [tblist deleteRowsAtIndexPaths:[NSArray arrayWithObject:[NSIndexPath indexPathForRow:indexToRemove inSection:0]] withRowAnimation:UITableViewRowAnimationNone];
        }
    }
}
4

2 に答える 2

2
- (void)viewDidLoad {
    [super viewDidLoad];
    dictBtnStatus = [[NSMutableDictionary alloc] init];
    arraylist = [[NSMutableArray alloc] init];
    array5 = [[NSMutableArray alloc] init];
    array1 = [[NSMutableArray alloc] init];
    objects = @[@"Medical Services In Chicago", @"Medical Services On Campus", @"ABC", @"California"];
    // objects = @[@"Medical Services In Chicago", @"Medical Services On Campus"];
    arrObjectValueChicago = @[@"Ronald McDonald® Children's Hospital of Loyola", @"Burn Centers", @"Gottlieb Hospitals"];
    arrObjectValueCampus = @[@"Cardinal Bernardin Cancer Center1", @"Center for Heart & Vascular Medicine2", @"ABC"];
    for (int i = 0; i < [arrObjectValueCampus count]; i++) {
        dictListCampus1 = [[NSDictionary alloc]initWithObjectsAndKeys:@"2", @"level",[arrObjectValueCampus objectAtIndex:i], @"name", nil];
        [array5 addObject:dictListCampus1];
    }
    NSDictionary *dictListCampus = [[NSDictionary alloc]initWithObjectsAndKeys:@"Wellness Centers", @"name", @"1", @"level", array5, @"Objects", nil];
    NSMutableArray *array6 = [[NSMutableArray alloc] initWithObjects:dictListCampus, nil];
    NSDictionary *dictListCampus2 = [[NSDictionary alloc] initWithObjectsAndKeys:@"Wellness Centers123", @"name", @"1", @"level", array5, @"Objects", nil];
    NSMutableArray *array61 = [[NSMutableArray alloc] initWithObjects:dictListCampus2, nil];
    array3 = [[NSMutableArray alloc] init];
    for (int i = 0; i < [arrObjectValueChicago count]; i++) {
        dictList3 = [[NSDictionary alloc] initWithObjectsAndKeys:@"2", @"level",[arrObjectValueChicago objectAtIndex:i], @"name", nil];
        [array3 addObject:dictList3];
    }

    NSDictionary *dictList2 = [[NSDictionary alloc] initWithObjectsAndKeys:@"Hospitals", @"name", @"1", @"level", array3, @"Objects", nil];
    NSMutableArray *array2 = [[NSMutableArray alloc] initWithObjects:dictList2, nil];
    for (int i = 0; i < [objects count]; i++) {
        if (i == 0) {
            dictionary = [[NSDictionary alloc] initWithObjectsAndKeys:[objects objectAtIndex:0], @"name", @"0", @"level", array2, @"Objects", nil];
            [array1 addObject:dictionary];
        } else if (i == 1) {
            dictionary = [[NSDictionary alloc] initWithObjectsAndKeys:[objects objectAtIndex:1], @"name", @"0", @"level", array6, @"Objects", nil];
            [array1 addObject:dictionary];
        } else if (i == 2) {
            dictionary = [[NSDictionary alloc] initWithObjectsAndKeys:[objects objectAtIndex:2], @"name", @"0", @"level", array61, @"Objects", nil];
            [array1 addObject:dictionary];
        }
      // else {
      //    dictionary = [[NSDictionary alloc] initWithObjectsAndKeys:[objects objectAtIndex:3], @"name", @"0", @"level", array2, @"Objects", nil];
      //    [array1 addObject:dictionary];
      //}
    }
    dictList = [[NSDictionary alloc] initWithObjectsAndKeys:array1, @"Objects", nil];
    NSLog(@"DictList :: %@", dictList);
    arrayOriginal = [dictList valueForKey:@"Objects"];
    NSLog(@"Array Original :: %@", arrayOriginal);
    [arraylist addObjectsFromArray:arrayOriginal];

    //[tblist.delegate tableView:tblist didSelectRowAtIndexPath:[NSIndexPath indexPathForRow:0 inSection:0]];
    //[tblist.delegate tableView:tblist didSelectRowAtIndexPath:[NSIndexPath indexPathForRow:1 inSection:0]];
}

#pragma mark - TableView
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
    return 1;
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
   return [arraylist count];
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    //static NSString *CellIdentifier = @"CustomCellIdentifier";
    NSUInteger IndentLevel = [[[arraylist objectAtIndex:indexPath.row] valueForKey:@"level"] intValue];
    UITableViewCell *cell = (UITableViewCell *)[tableView dequeueReusableCellWithIdentifier:@"Cell"];
    if (IndentLevel == 0) {
        CustomCellHeader *cell = (CustomCellHeader *)[tableView dequeueReusableCellWithIdentifier:@"CellIdentifier"];
        if (cell == nil) {
            [[NSBundle mainBundle]loadNibNamed:@"CustomCellHeader" owner:self options:nil];
            cell = self.headercell;
            self.headercell = nil;
        }
        cell.lblHeader.text = [[arraylist objectAtIndex:indexPath.row] valueForKey:@"name"];
        [cell setIndentationLevel:[[[arraylist objectAtIndex:indexPath.row] valueForKey:@"level"] intValue]];
        NSLog(@"indexFor level 0 ::%@ %d",cell.lblHeader.text, indexPath.row);
        return cell;
    } else if (IndentLevel == 1) {
        CustomCellSubHeader *cell = (CustomCellSubHeader *)[tableView dequeueReusableCellWithIdentifier:@"CellIdentifier"];
        if (!cell) {
            [[NSBundle mainBundle]loadNibNamed:@"CustomCellSubHeader" owner:self options:nil];
            cell = self.subheadercell;
            self.subheadercell = nil;
            NSLog(@"dicbtn %@", dictBtnStatus);
        }
        NSString *strName = [[arraylist objectAtIndex:indexPath.row] valueForKey:@"name"];
        NSString *str = [dictBtnStatus objectForKey:strName];
        NSLog(@"indexFor level 1 ::%@ %d", strName, indexPath.row);
        if ([str isEqualToString:@"1"]) {
            [cell.btnarrow setImage:[UIImage imageNamed:@"dwn1_arow.png"] forState:UIControlStateNormal];
            [cell.imgSubHeader setImage:[UIImage imageNamed:@"tab_active.png"]];
        }
      // else {
      //    [cell.imgSubHeader setImage:[UIImage imageNamed:@"tab_default.png"]];
      //}
        cell.lblSubHeader.text = strName;
        [cell setIndentationLevel:[[[arraylist objectAtIndex:indexPath.row] valueForKey:@"level"] intValue]];

        if (indexPath.row == arraylist.count - 1) {
            cell.imgShadow.hidden = NO;
        }
        return cell;
    } else if (IndentLevel == 2) {
        CustomCell *cell = (CustomCell *)[tableView dequeueReusableCellWithIdentifier:@"CellIdentifier"];
        if (cell == nil) {
            [[NSBundle mainBundle]loadNibNamed:@"CustomCell" owner:self options:nil];
            cell = self.cells;
            self.cells = nil;
        }
        cell.txtAddress.text = [[arraylist objectAtIndex:indexPath.row] valueForKey:@"name"];
        [cell.btnCall addTarget:self action:@selector(btnCall:) forControlEvents:UIControlEventTouchUpInside];
        [cell setIndentationLevel:[[[arraylist objectAtIndex:indexPath.row] valueForKey:@"level"] intValue]];
        return cell;
    }
    return cell;
}

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
    CustomCellSubHeader *cell;
    if ([[tblist cellForRowAtIndexPath:indexPath] isKindOfClass:[CustomCellSubHeader class]]) {
        cell = (CustomCellSubHeader*)[tblist cellForRowAtIndexPath:indexPath];
        UIImage *img = [cell.btnarrow imageForState:UIControlStateNormal];
        if ([img isEqual:[UIImage imageNamed:@"dwn1_arow.png"]]) {
            [cell.btnarrow setImage:[UIImage imageNamed:@"gry_arrow.png"] forState:UIControlStateNormal];
            [dictBtnStatus setValue:@"0" forKey:cell.lblSubHeader.text];
            [cell.imgSubHeader setImage:[UIImage imageNamed:@"tab_default.png"]];
            cell.imgShadow.hidden = NO;
        } else {
            [cell.btnarrow setImage:[UIImage imageNamed:@"dwn1_arow.png"] forState:UIControlStateNormal];
            dictBtnStatus = [[NSMutableDictionary alloc] init];
            [dictBtnStatus setValue:@"1" forKey:cell.lblSubHeader.text];
            [cell.imgSubHeader setImage:[UIImage imageNamed:@"tab_active.png"]];
            cell.imgShadow.hidden = YES;
        }
    }
    NSMutableArray *arrIndex = [[NSMutableArray alloc] init];
    NSUInteger IndentLevel = [[[arraylist objectAtIndex:indexPath.row] valueForKey:@"level"] intValue];
    if (IndentLevel == 0) {
        arrLast = [[NSMutableArray alloc] init];
    }
    [tableView deselectRowAtIndexPath:indexPath animated:YES];
    NSDictionary *d = [arraylist objectAtIndex:indexPath.row];
    if ([d valueForKey:@"Objects"]) {
        NSArray *ar = [d valueForKey:@"Objects"];
        BOOL isAlreadyInserted = NO;
        for (NSDictionary *dInner in ar) {
            NSInteger index = [arraylist indexOfObjectIdenticalTo:dInner];
            isAlreadyInserted = (index > 0 && index != NSIntegerMax);
            if (isAlreadyInserted) break;
        }
        if (isAlreadyInserted) {
            [self miniMizeThisRows:ar];
        } else {
            NSUInteger count = indexPath.row + 1;
            NSMutableArray *arCells = [NSMutableArray array];
            for (NSDictionary *dInner in ar) {
                [arCells addObject:[NSIndexPath indexPathForRow:count inSection:0]];
                [arrLast addObject:dInner];
                [arraylist insertObject:dInner atIndex:count++];
            }
            [tableView insertRowsAtIndexPaths:arCells withRowAnimation:UITableViewRowAnimationBottom];
        }
    }
    //NSUInteger IndentLevel = [[[arraylist objectAtIndex:indexPath.row] valueForKey:@"level"] intValue];
    if (IndentLevel == 0) {
        NSMutableIndexSet *discardedItems = [NSMutableIndexSet indexSet];
        for (int i = 0 ; i < arraylist.count; i++) {
            NSDictionary *dic = [arraylist objectAtIndex:i];
            if ([[dic valueForKey:@"level"] intValue] != 0) {
                NSInteger index = [arrLast indexOfObjectIdenticalTo:dic];
                if ((index >= 0 && index != NSIntegerMax)) {
                } else {
                    [discardedItems addIndex:i];
                    [arrIndex addObject:[NSIndexPath indexPathForRow:i inSection:0]];
                }
            }
        }
        if (discardedItems.count > 0) {
            [arraylist removeObjectsAtIndexes:discardedItems];
            [tblist deleteRowsAtIndexPaths:arrIndex withRowAnimation:UITableViewRowAnimationNone];
        }
    }
}

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {
    NSUInteger indentLevel = [[[arraylist objectAtIndex:indexPath.row] valueForKey:@"level"] intValue];
    if (indentLevel == 0) {            
        return 40;
    } else if (indentLevel == 1) {
        return 25;
    } else if (indentLevel == 2) {
        CustomCell *cell = ((CustomCell *)[tableView dequeueReusableCellWithIdentifier:@"CellIdentifier"]);
        CGSize maximumSize = CGSizeMake(300, 9999);
        UIFont *myFont = [UIFont fontWithName:@"Arial" size:11.5];
        CGSize myStringSize = [cell.txtAddress.text sizeWithFont:myFont constrainedToSize:maximumSize lineBreakMode:NSLineBreakByWordWrapping];
        [cell.txtAddress setFrame:CGRectMake(cell.txtAddress.frame.origin.x, cell.txtAddress.frame.origin.y, cell.txtAddress.frame.size.width, myStringSize.height)];

        if (myStringSize.height > 80) {
            myStringSize.height = 50;
            [cell.txtAddress setFrame:CGRectMake(cell.txtAddress.frame.origin.x, cell.txtAddress.frame.origin.y, cell.txtAddress.frame.size.width, myStringSize.height)];
            cell.txtAddress.scrollEnabled = YES;
        } else {
            cell.txtAddress.scrollEnabled = YES;
            myStringSize.height = 40;
        }
        return myStringSize.height + 50;
    } else return 25;
}

#pragma mark - TableAnimation
- (void)miniMizeThisRows:(NSArray *)ar {
    for (NSDictionary *dInner in ar) {
        NSUInteger indexToRemove = [arraylist indexOfObjectIdenticalTo:dInner];
        NSArray *arInner=[dInner valueForKey:@"Objects"];
        if (arInner && [arInner count] > 0) {
            [self miniMizeThisRows:arInner];
        }

        if ([arraylist indexOfObjectIdenticalTo:dInner] != NSNotFound) {
            [arraylist removeObjectIdenticalTo:dInner];
            [tblist deleteRowsAtIndexPaths:[NSArray arrayWithObject:[NSIndexPath indexPathForRow:indexToRemove inSection:0]] withRowAnimation:UITableViewRowAnimationNone];
        }
    }
}

#pragma mark - Buttons
- (IBAction)btnCall:(id)sender {
    UIAlertView *Notpermitted = [[UIAlertView alloc] initWithTitle:@"Alert" message:@"Do you want to call on this number." delegate:nil cancelButtonTitle:@"NO" otherButtonTitles:@"YES", nil];
    Notpermitted.delegate = self;
    [Notpermitted tag];
    [Notpermitted show];
}

- (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex {
    if (buttonIndex == 1) {
        NSString *strCall = [NSString stringWithFormat:@"tel://999-999-9999"];
        NSURL *url = [NSURL URLWithString:strCall];
        UIDevice *device = [UIDevice currentDevice];
        if ([[device model] isEqualToString:@"iPhone"] ) {
            [[UIApplication sharedApplication] openURL:url];
        } else {
            UIAlertView *Notpermitted = [[UIAlertView alloc] initWithTitle:@"Alert" message:@"Your device doesn't support this feature." delegate:nil cancelButtonTitle:@"OK" otherButtonTitles:nil];
            [Notpermitted show];
        }
    }
}
于 2013-06-03T12:34:33.023 に答える
1

次のチュートリアルを参照してください

http://www.cocoanetics.com/2011/03/expandingcollapsing-tableview-sections/

www.alexandre-gomes.com/?p=482

iOS の UITableView でセクションを展開/折りたたむ

于 2013-05-08T10:11:08.857 に答える