zoukankan      html  css  js  c++  java
  • 点击UITableviewCell展开收缩

    #import "ViewController.h"
    #import "ZSDTestCell.h"
    @interface ViewController ()<UITableViewDataSource,UITableViewDelegate>
    {
        
        NSMutableArray *dataArray;    //数组保存显示内容
        NSIndexPath *selectIndex;     //记录当前选择的索引
    }
    
    
    @end
    
    @implementation ViewController
    
    - (void)viewDidLoad
    {
        [super viewDidLoad];
        dataArray=[NSMutableArray array];
        for (int i=0; i<20; i++) {
            [dataArray addObject:[NSString stringWithFormat:@"%d",i]];
        }
        selectIndex=nil;
    }
    
    -(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
    {
    
        return dataArray.count;
        
    }
    -(NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
    {
        return 1;
        
    }
    -(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
    {
        
        if (indexPath==selectIndex)
        {
            return 88.0;
        }
        return 44.0f;
    }
    
    -(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
    {
        UIImage *normalImg = [UIImage imageNamed:@"member_icon_more"];
        UIImage *selectImg = [UIImage imageNamed:@"common_icon_down"];
        ZSDTestCell *testCell=[tableView dequeueReusableCellWithIdentifier:@"ZSDTestCell" forIndexPath:indexPath];
        testCell.firstLabel.text=dataArray[indexPath.row];
        if (selectIndex==indexPath)
        {
            testCell.remindImageView.image=selectImg;
            testCell.secondLabel.text=[NSString stringWithFormat:@"测试第%@行UITableviewCell收缩效果",dataArray[indexPath.row]];
        }
        else
        {
            testCell.remindImageView.image=normalImg;
            testCell.secondLabel.text=nil;
        }
        return testCell;
    }
    -(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
    {
        if(selectIndex==nil)
        {
            selectIndex=indexPath;
        }
        else
        {
            bool selectedOtherRow=![selectIndex isEqual:indexPath];
            selectIndex=nil;
            if(selectedOtherRow)
            {
                selectIndex=indexPath;
            }
        }
       [tableView reloadData];
    }
    
    @end

  • 相关阅读:
    SpringBoot使用SpringSession和redis解决session共享问题(nginx反向代理)
    centos7中安装和配置nginx和keepalived
    定位
    css
    css美化
    html5
    列表,表格,媒体元素
    表单
    一期测试错题修改
    字符串
  • 原文地址:https://www.cnblogs.com/thbbsky/p/4255416.html
Copyright © 2011-2022 走看看