码迷,mamicode.com
首页 > 其他好文 > 详细

点击UITableviewCell展开收缩

时间:2015-01-28 12:30:52      阅读:216      评论:0      收藏:0      [点我收藏+]

标签:

#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

技术分享

点击UITableviewCell展开收缩

标签:

原文地址:http://www.cnblogs.com/thbbsky/p/4255416.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!