學習筆記

【學習筆記】tableview 簡單用法,加圖片,文字數組,鎖定不滾動
分類: 【學習筆記】 2015-04-04 22:01 1人閱讀 評論(0) 收藏 舉報
// FourViewController.h

@interface FourViewController : UIViewController

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.
    }
發佈了13 篇原創文章 · 獲贊 1 · 訪問量 1萬+
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章