【学习笔记】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.
}
- 【学习笔记】tableview 简单用法,加图片,文字数组,锁定不滚动
- 图片加文字链接,不显示文字
- tableview header不滚动
- 简单的图片、文字滚动效果
- 兼容ie.ff 的滚动图片加文字代码
- JMagick 学习六:图片加中文字
- UIbutton 按钮加图片后文字显示不出来解决方案
- 学习笔记-图片加水印
- headerVIew不随tableView 滚动
- 滚动文字、滚动图片代码
- div 图片滚动 / 文字滚动
- java图片加文字
- uibutton 图片加文字
- android 图片加文字
- 图片加文字水印
- 图片上加文字
- 图片加水印文字
- 图片 文字 同时滚动
- 【C语言】 写一个递归函数DigitSum(n),返回组成它的数字之和
- awk统计文本中同一数据出现的次数排序(转)
- 《unix网络编程》(13)select、shutdown函数
- qq列表,每组之间互不干扰
- PostgreSQL 添加各种约束语法
- 【学习笔记】tableview 简单用法,加图片,文字数组,锁定不滚动
- 工厂模式(c++描述)
- Unity动画 Animator的属性
- servlet.jar--jar not loaded错误
- BestCoder Round #36 ($)(一、二题解题报告)
- 树莓派2 安装ARCH LINUX ARM系统后I2C和SPI的配置
- 14. PHP Array数组(2)
- Bestcoder #36 hash
- hdu5200 Trees