【学习笔记】tableview 简单用法,加图片,文字数组,锁定不滚动

//  FourViewController.h



@interface FourViewController : UIViewController<UITableViewDataSource,UITableViewDelegate>


//tableview声明几个数组,因为打算分三个区,文字,图片都有

@property(nonatomic,retain)NSArray*text_Array1;

@property(nonatomic,retain)NSArray*text_Array2;

@property(nonatomic,retain)NSArray*text_Array3;


@property(nonatomic,retain)NSArray*picture_Array1;

@property(nonatomic,retain)NSArray*picture_Array2;

@property(nonatomic,retain)NSArray*picture_Array3;


@end



//  FourViewController.m

#import "FourViewController.h"

@interface FourViewController ()

@end


@implementation FourViewController


@synthesize text_Array1;

@synthesize text_Array2;

@synthesize text_Array3;

@synthesize picture_Array1;

@synthesize picture_Array2;

@synthesize picture_Array3;


表格栏tabbarview/

//创建数组

    NSArray*tArray1=[[NSArray alloc]initWithObjects:@"余额宝",@"找财报",@"娱乐宝", nil];

    text_Array1=tArray1;


    NSArray*tArray2=[[NSArray alloc]initWithObjects:@"芝麻信用分",@"我的保障", nil];

    text_Array2=tArray2;

    

    NSArray*tArray3=[[NSArray alloc]initWithObjects:@"爱心捐赠", nil];

    text_Array3=tArray3;

    

    NSArray*pArray1=[[NSArray alloc]initWithObjects:[UIImage imageNamed:@"1"], [UIImage imageNamed:@"2"],[UIImage imageNamed:@"3"],nil];

    picture_Array1=pArray1;

    

    NSArray*pArray2=[[NSArray alloc]initWithObjects:[UIImage imageNamed:@"4"],[UIImage imageNamed:@"5"],nil];

    picture_Array2=pArray2;

    

    NSArray*pArray3=[[NSArray alloc]initWithObjects:[UIImage imageNamed:@"6"],nil];

    picture_Array3=pArray3;

    

//创建tableview关键,不要少了代理,位置自己调

    UITableView*cf_tableview=[[UITableView alloc]initWithFrame:CGRectMake(0, zl_view1.bounds.size.height+nav_View.bounds.size.height+20+yhk_view3.bounds.size.height, self.view.bounds.size.width, 500) style:UITableViewStyleGrouped];


    cf_tableview.delegate=self;

    cf_tableview.dataSource=self;

    

    [cf_tableview setScrollEnabled:NO];     //不能滚动

    

    [self.view addSubview:cf_tableview];

    

}



//多少组

-(NSInteger)numberOfSectionsInTableView:(UITableView *)tableView

{

    return 3;

}


//每组多少个

-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section

{

    if (section==0) {

        return 3;

    }else if (section==1){

        return 2;

    }else

        return 1;

}


//创建cell,导入数组内容

-(UITableViewCell*)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath

{

    static NSString*CellIdentifier=@"Cell";

    UITableViewCell*cell=[tableView dequeueReusableCellWithIdentifier:CellIdentifier];


    if (cell==nil) {

        cell=[[UITableViewCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier];

    }

    

    

    if (indexPath.section==0) {

        cell.textLabel.text=[text_Array1 objectAtIndex:[indexPath row]];

        cell.imageView.image=[picture_Array1 objectAtIndex:[indexPath row]];

        

    }else if (indexPath.section==1){

        cell.textLabel.text=[text_Array2 objectAtIndex:[indexPath row]];

        cell.imageView.image=[picture_Array2 objectAtIndex:[indexPath row]];

        

    }else{

        cell.textLabel.text=[text_Array3 objectAtIndex:[indexPath row]];

        cell.imageView.image=[picture_Array3 objectAtIndex:[indexPath row]];

    }

    return cell;

}


分区的间距,头,尾

-(CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section

{

    return 15;

}

-(CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section

{

    return 1;

}






- (void)didReceiveMemoryWarning

{

    [super didReceiveMemoryWarning];

    // Dispose of any resources that can be recreated.

}



评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值