中文字幕在线观看,亚洲а∨天堂久久精品9966,亚洲成a人片在线观看你懂的,亚洲av成人片无码网站,亚洲国产精品无码久久久五月天

自定義UITableView折疊效果

2018-07-20    來源:open-open

容器云強勢上線!快速搭建集群,上萬Linux鏡像隨意使用
類似于QQ的那種折疊效果。只刷新點擊的折疊行。不加載所有數(shù)據(jù)源。 測試環(huán)境Xcode4.3.3+SDK5.1兼容ios6
//
//  MyTableViewController.m
//  TableSectionStatistics
//

#import "MyTableViewController.h"
#define originalHeight 25.0f
#define newHeight 85.0f
#define isOpen @"85.0f"

@interface MyTableViewController ()

@end

@implementation MyTableViewController
{
    NSMutableDictionary *dicClicked;
    NSInteger count;
    CGFloat mHeight;
    NSInteger sectionIndex;
}

- (id)initWithStyle:(UITableViewStyle)style
{
    self = [super initWithStyle:style];
    if (self) {
        // Custom initialization
    }
    return self;
}

- (void)viewDidLoad
{
    [super viewDidLoad];
    count = 0;
    mHeight = originalHeight;
    sectionIndex = 0;
    dicClicked = [NSMutableDictionary dictionaryWithCapacity:3];
}

- (void)viewDidUnload
{
    [super viewDidUnload];
    // Release any retained subviews of the main view.
    // e.g. self.myOutlet = nil;
}

#pragma mark - Table view data source

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
    // Return the number of sections.
    return 50;
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    return 2;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{    
    static NSString *contentIndentifer = @"Container";
    if (indexPath.row == 0) {
        UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:contentIndentifer];
        if (cell == nil) {
            cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:contentIndentifer];
        }
        NSString *statisticsContent = [[NSString alloc] initWithString:@"rlf:歲月流芳,花開幾度,走在歲月里,醉在流香里,總在時光里輾轉(zhuǎn)徘徊;ㄩ_幾許,落花幾度,歲月寒香,飄進誰的詩行,一抹幽香,摻入幾許愁傷,流年似花,春來秋往,睜開迷離的雙眼,回首張望,隨風的塵煙蕩漾著迷忙,昨日的光陰已逝去,留下無盡的回憶讓人留戀與追憶"];
        cell.textLabel.font = [UIFont systemFontOfSize:12.0f];
        cell.textLabel.text = statisticsContent;
        cell.textLabel.textColor = [UIColor brownColor]
        ;
        cell.textLabel.opaque = NO; // 選中Opaque表示視圖后面的任何內(nèi)容都不應該繪制        
        cell.textLabel.numberOfLines = 8;        
        cell.selectionStyle = UITableViewCellSelectionStyleNone;
        return cell;
    }
    static NSString *CellIdentifier = @"Cell";
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
    if (cell == nil) {
        cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier];
    }
    cell.imageView.image = [UIImage imageNamed:@"ic_milestone_heart.png"];
    cell.textLabel.text = [NSString stringWithFormat:@"%d",count];
    count++;
    return cell;
}

//Section的標題欄高度
-(CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section
{
    if (section == 0)
        return 46;
    else
        return 30.0f;
}

-(UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section
{
    CGRect headerFrame = CGRectMake(0, 0, 300, 30);
    CGFloat y = 2;
    if (section == 0) {
        headerFrame = CGRectMake(0, 0, 300, 100);
        y = 18;
    }
    UIView *headerView = [[UIView alloc] initWithFrame:headerFrame];
    UILabel *dateLabel=[[UILabel alloc] initWithFrame:CGRectMake(20, y, 240, 24)];//日期標簽
    dateLabel.font=[UIFont boldSystemFontOfSize:16.0f];
    dateLabel.textColor = [UIColor darkGrayColor];
    dateLabel.backgroundColor=[UIColor clearColor];
    UILabel *ageLabel=[[UILabel alloc] initWithFrame:CGRectMake(216, y, 88, 24)];//年齡標簽
    ageLabel.font=[UIFont systemFontOfSize:14.0];
    ageLabel.textAlignment=UITextAlignmentRight;
    ageLabel.textColor = [UIColor darkGrayColor];
    ageLabel.backgroundColor=[UIColor clearColor];

    NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init];
    dateFormatter.dateFormat = @"MM dd,yyyy";
    dateLabel.text = [NSString stringWithFormat:@"%@",[dateFormatter stringFromDate:[NSDate date]]];
    ageLabel.text = @"1歲 2天";

    [headerView addSubview:dateLabel];
    [headerView addSubview:ageLabel];
    return headerView;
}

#pragma mark - Table view delegate

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    if (indexPath.row == 0) {   
        UITableViewCell *targetCell = [tableView cellForRowAtIndexPath:indexPath];
        if (targetCell.frame.size.height == originalHeight+1){          
            [dicClicked setObject:isOpen forKey:indexPath];
        }
        else{     
            [dicClicked removeObjectForKey:indexPath];
        }       
      [self.tableView reloadRowsAtIndexPaths:[NSArray arrayWithObject:indexPath] withRowAnimation:UITableViewRowAnimationFade];
    }
    NSLog(@"indexPath=%@",indexPath);
    NSLog(@"dicClicked=%@",dicClicked);
}

-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
    if (indexPath.row == 0) {
        if ([[dicClicked objectForKey:indexPath] isEqualToString: isOpen]) 
            return [[dicClicked objectForKey:indexPath] floatValue];
        else
            return originalHeight;     
    }
    else {
        return 45.0f;
    }
}

@end
 

標簽:

版權申明:本站文章部分自網(wǎng)絡,如有侵權,請聯(lián)系:west999com@outlook.com
特別注意:本站所有轉(zhuǎn)載文章言論不代表本站觀點!
本站所提供的圖片等素材,版權歸原作者所有,如需使用,請與原作者聯(lián)系。

上一篇:android獲得json數(shù)據(jù)并處理

下一篇:objective-c產(chǎn)生隨機數(shù)的方法