day 024UITableView

主要讲解了UITableView的一些性质与应用

还有重写cell

//
//  ViewController.h
//  UiTableView
//
//  Created by dashen on 15-4-27.
//  Copyright (c) 2015年 李灵杰. All rights reserved.
//


#import <UIKit/UIKit.h>
#import "WeChatCell.h"


@interface ViewController : UIViewController<UITableViewDataSource,UITableViewDelegate>




@end



//
//  ViewController.m
//  UiTableView
//
//  Created by dashen on 15-4-27.
//  Copyright (c) 2015年 李灵杰. All rights reserved.
//


#import "ViewController.h"
#import "WeChatCell.h"


@interface ViewController ()
@property (nonatomic,strong) UITableView *uiTableView;
@end


@implementation ViewController
            
- (void)viewDidLoad {
    [super viewDidLoad];
    self.uiTableView = [[UITableView alloc]initWithFrame:self.view.bounds style:UITableViewStyleGrouped];
    _uiTableView.delegate = self;
    _uiTableView.dataSource = self;
    [self.view addSubview:_uiTableView];
}


- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}


- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
    return 80;
}


//设置行
-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    return 4;
}


-(WeChatCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    NSString *cellID = @"cellID";
    
    //先不忙着创建cell,表示图有一个队列,当cell移出界面(消失),消失的cell将会被扔到表示图的队列中去
    //首先从这个队列里面去查看有没有可以重复利用的cell  这个cell的标识符是cellID,如果有直接返回这个cell
    //如果不存在返回nil
    WeChatCell *cell = [tableView dequeueReusableCellWithIdentifier:cellID];
    
    //判断是否存在
    if(cell==nil){
        //如果不存在 ,就自己创建一个cell,加上标签
        cell = [[WeChatCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellID];
        NSLog(@"%ld",indexPath.row);
    }
    
    cell.headerImageView.image = [UIImage imageNamed:@"wechat"];
    return cell;
}


/*
//设置段
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView{
    return 27;
}


//设置每段的头header
- (NSString *)tableView:(UITableView *)tableView titleForHeaderInSection:(NSInteger)section{
    return [NSString stringWithFormat:@"%c",'A'+(int)section];
}


//设置每段段尾footer
- (NSString *)tableView:(UITableView *)tableView titleForFooterInSection:(NSInteger)section{
return @"bye";
}


//添加右侧索引表
- (NSArray *)sectionIndexTitlesForTableView:(UITableView *)tableView{
    NSMutableArray *titlesArray = [NSMutableArray arrayWithCapacity:27];
    for (int i= 0;i<26;i++){
        NSString *alphaString = [NSString stringWithFormat:@"%c",'A'+i];
        [titlesArray addObject:alphaString];
        
    }
    return titlesArray;
}


- (BOOL)tableView:(UITableView *)tableView canEditRowAtIndexPath:(NSIndexPath *)indexPath{
    if (indexPath.section == 0) {
        return NO;
    }else{
        return YES;
    }
}


- (UITableViewCellEditingStyle)tableView:(UITableView *)tableView editingStyleForRowAtIndexPath:(NSIndexPath *)indexPath{
    return UITableViewCellEditingStyleDelete | UITableViewCellEditingStyleInsert;
}


- (NSString *)tableView:(UITableView *)tableView titleForDeleteConfirmationButtonForRowAtIndexPath:(NSIndexPath *)indexPath{
    return @"删除";
}


- (void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath{
    NSLog(@"commit");
}


-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
    //取消选中状态
    [self.uiTableView deselectRowAtIndexPath:indexPath animated:YES];
    NSLog(@"selected");
}


- (void)tableView:(UITableView *)tableView didDeselectRowAtIndexPath:(NSIndexPath *)indexPath{
    NSLog(@"deselect");
}


- (IBAction)EditBarButton:(UIBarButtonItem *)sender {
    if([sender.title isEqualToString:@"Edit"]){
        [sender setTitle:@"Done"];
        [self.uiTableView setEditing:YES animated:YES];
    }else {
        [sender setTitle:@"Edit"];
        [self.uiTableView setEditing:NO animated:YES];
    }
}


*/


@end


//
//  WeChatCell.h
//  UiTableView
//
//  Created by dashen on 15-4-28.
//  Copyright (c) 2015年 李灵杰. All rights reserved.
//


#import <UIKit/UIKit.h>


@interface WeChatCell : UITableViewCell
@property (nonatomic,strong) UIImageView *headerImageView;
@end


//
//  WeChatCell.m
//  UiTableView
//
//  Created by dashen on 15-4-28.
//  Copyright (c) 2015年 李灵杰. All rights reserved.
//


#import "WeChatCell.h"


@interface WeChatCell ()


@end


@implementation WeChatCell




- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
    
    if (self= [super initWithStyle:style reuseIdentifier:reuseIdentifier]) {
        self.headerImageView = [[UIImageView alloc]initWithFrame:CGRectMake(10, 10, 60, 60)];
        [self.contentView addSubview:_headerImageView];
    }
    return self;
}


@end

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值