Chinaunix首页 | 论坛 | 博客
  • 博客访问: 79743
  • 博文数量: 35
  • 博客积分: 1772
  • 博客等级: 上尉
  • 技术积分: 375
  • 用 户 组: 普通用户
  • 注册时间: 2010-04-08 14:39
文章分类
文章存档

2012年(1)

2011年(16)

2010年(18)

我的朋友

分类: 嵌入式

2011-06-21 12:54:01

创建 UITableView

UITableView *tableView;

tableView = [[UITableView alloc] initWithFrame : CGRectMake(0,0,320,420)];
[tableView setDetegate:self];
[tableView setDataSource:self];

显示 UITableView

[self.view addSubview : tableView];

UITableView 方法简介:

//Section总数
- (NSArray *)sectionIndexTitlesForTab

leView:(UITableView *)tableView{
 return TitleData;
}


// Section Titles
//每个section显示的标题
- (NSString *)tableView:(UITableView *)tableView titleForHeaderInSection:(NSInteger)section{
 return @"";
}


//指定有多少个分区(Section),默认为1
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
 return 4;
}


//指定每个分区中有多少行,默认为1
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
}


//绘制Cell
-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
static NSString *SimpleTableIdentifier = @"SimpleTableIdentifier";
  
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:
                             SimpleTableIdentifier];
    if (cell == nil) {  
        cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault
                                       reuseIdentifier: SimpleTableIdentifier] autorelease];
 }
 cell.imageView.image=image;//未选cell时的图片
 cell.imageView.highlightedImage=highlightImage;//选中cell后的图片
 cell.text=//.....
 return cell;
}


//行缩进
-(NSInteger)tableView:(UITableView *)tableView indentationLevelForRowAtIndexPath:(NSIndexPath *)indexPath{
 NSUInteger row = [indexPath row];
 return row;
}


//改变行的高度
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
    return 40;
}


/选中Cell响应事件
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{

 [tableView deselectRowAtIndexPath:indexPath animated:YES];//选中后的反显颜色即刻消失
}


阅读(1024) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~