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

来源:互联网 发布:java生成二维码图片 编辑:程序博客网 时间:2024/06/06 05:26

//  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=[[NSArrayalloc]initWithObjects:@"余额宝",@"找财报",@"娱乐宝",nil];

   text_Array1=tArray1;


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

   text_Array2=tArray2;

    

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

   text_Array3=tArray3;

    

    NSArray*pArray1=[[NSArrayalloc]initWithObjects:[UIImageimageNamed:@"1"], [UIImageimageNamed:@"2"],[UIImageimageNamed:@"3"],nil];

    picture_Array1=pArray1;

    

    NSArray*pArray2=[[NSArrayalloc]initWithObjects:[UIImageimageNamed:@"4"],[UIImageimageNamed:@"5"],nil];

    picture_Array2=pArray2;

    

    NSArray*pArray3=[[NSArrayalloc]initWithObjects:[UIImageimageNamed:@"6"],nil];

    picture_Array3=pArray3;

    

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

    UITableView*cf_tableview=[[UITableViewalloc]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_tableviewsetScrollEnabled:NO];    //不能滚动

    

    [self.viewaddSubview:cf_tableview];

    

}



//多少组

-(NSInteger)numberOfSectionsInTableView:(UITableView *)tableView

{

   return 3;

}


//每组多少个

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

{

   if (section==0) {

       return 3;

    }elseif (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=[[UITableViewCellalloc]initWithStyle:UITableViewCellStyleDefaultreuseIdentifier:CellIdentifier];

    }

    

    

   if (indexPath.section==0) {

        cell.textLabel.text=[text_Array1objectAtIndex:[indexPath row]];

        cell.imageView.image=[picture_Array1objectAtIndex:[indexPath row]];

        

    }elseif (indexPath.section==1){

        cell.textLabel.text=[text_Array2objectAtIndex:[indexPath row]];

        cell.imageView.image=[picture_Array2objectAtIndex:[indexPath row]];

        

    }else{

        cell.textLabel.text=[text_Array3objectAtIndex:[indexPath row]];

        cell.imageView.image=[picture_Array3objectAtIndex:[indexPath row]];

    }

   return cell;

}


////////////////////////////分区的间距,头,尾////////////////////////

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

{

   return 15;

}

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

{

   return 1;

}






- (void)didReceiveMemoryWarning

{

    [superdidReceiveMemoryWarning];

    // Dispose of any resources that can be recreated.

}



0 0
原创粉丝点击