QQ好友列表,点击折叠展开

@property (assign) BOOL  isOpen;
 
  self.isOpen = NO;
 
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
 
     return  [_dataList count];
}
 
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
     if  (self.isOpen) {
         if  (self.selectIndex.section == section) {
             return  [[[_dataList objectAtIndex:section] objectForKey:@ "list" ] count]+1;;
         }
     }
     return  1;
}
 
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
     return  40;
}
 
 
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
     if  (self.isOpen&&self.selectIndex.section == indexPath.section&&indexPath.row!=0) {
         static  NSString *CellIdentifier = @ "Cell2" ;
         Cell2 *cell = (Cell2*)[tableView dequeueReusableCellWithIdentifier:CellIdentifier];
         
         if  (!cell) {
             cell = [[[NSBundle mainBundle] loadNibNamed:CellIdentifier owner:self options:nil] objectAtIndex:0];
         }
         NSArray *list = [[_dataList objectAtIndex:self.selectIndex.section] objectForKey:@ "list" ];
         cell.titleLabel.text = [list objectAtIndex:indexPath.row-1];
         return  cell;
     } else
     {
         static  NSString *CellIdentifier = @ "Cell1" ;
         Cell1 *cell = (Cell1*)[tableView dequeueReusableCellWithIdentifier:CellIdentifier];
         if  (!cell) {
             cell = [[[NSBundle mainBundle] loadNibNamed:CellIdentifier owner:self options:nil] objectAtIndex:0];
         }
         NSString *name = [[_dataList objectAtIndex:indexPath.section] objectForKey:@ "name" ];
         cell.titleLabel.text = name;
         [cell changeArrowWithUp:([self.selectIndex isEqual:indexPath]?YES:NO)];
         return  cell;
     }
}
 
 
#pragma mark - Table view delegate
- ( void )tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
     if  (indexPath.row == 0) {
         if  ([indexPath isEqual:self.selectIndex]) {
             self.isOpen = NO;
             [self didSelectCellRowFirstDo:NO nextDo:NO];
             self.selectIndex = nil;
             
         } else
         {
             if  (!self.selectIndex) {
                 self.selectIndex = indexPath;
                 [self didSelectCellRowFirstDo:YES nextDo:NO];
                 
             } else
             {
                 
                 [self didSelectCellRowFirstDo:NO nextDo:YES];
             }
         }
         
     } else
     {
         NSDictionary *dic = [_dataList objectAtIndex:indexPath.section];
         NSArray *list = [dic objectForKey:@ "list" ];
         NSString *item = [list objectAtIndex:indexPath.row-1];
         UIAlertView *alert = [[[UIAlertView alloc] initWithTitle:item message:nil delegate:nil cancelButtonTitle:@ "取消"  otherButtonTitles: nil] autorelease];
         [alert show];
     }
     [tableView deselectRowAtIndexPath:indexPath animated:YES];
}
 
 
- ( void )didSelectCellRowFirstDo:( BOOL )firstDoInsert nextDo:( BOOL )nextDoInsert
{
     self.isOpen = firstDoInsert;
     
     Cell1 *cell = (Cell1 *)[self.expansionTableView cellForRowAtIndexPath:self.selectIndex];
     [cell changeArrowWithUp:firstDoInsert];
     
     [self.expansionTableView beginUpdates];
     
     NSInteger section = self.selectIndex.section;
     NSInteger contentCount = [[[_dataList objectAtIndex:section] objectForKey:@ "list" ] count];
     NSMutableArray* rowToInsert = [[NSMutableArray alloc] init];
     for  (NSUInteger i = 1; i < contentCount + 1; i++) {
         NSIndexPath* indexPathToInsert = [NSIndexPath indexPathForRow:i inSection:section];
         [rowToInsert addObject:indexPathToInsert];
     }
     
     if  (firstDoInsert)
     {   [self.expansionTableView insertRowsAtIndexPaths:rowToInsert withRowAnimation:UITableViewRowAnimationTop];
     }
     else
     {
         [self.expansionTableView deleteRowsAtIndexPaths:rowToInsert withRowAnimation:UITableViewRowAnimationTop];
     }
     
     [rowToInsert release];
     
     [self.expansionTableView endUpdates];
     if  (nextDoInsert) {
         self.isOpen = YES;
         self.selectIndex = [self.expansionTableView indexPathForSelectedRow];
         [self didSelectCellRowFirstDo:YES nextDo:NO];
     }
     if  (self.isOpen) [self.expansionTableView scrollToNearestSelectedRowAtScrollPosition:UITableViewScrollPositionTop animated:YES];
}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值