background image

IOS 之 UITableView 详解

一、建立

 UITableView  

       UITableView  *tabYwKPI  =  [[UITableView  alloc]initWithFrame:CGRectMake(0,  100,  320, 
366)];  
    tabYwKPI.separatorColor = [[UIColor alloc] initWithRed:0.8 green:0.8 blue:0.8 alpha:1];  
    tabYwKPI.tag=100;  
    tabYwKPI.scrollEnabled = YES;  
    tabYwKPI.dataSource = self;  
    tabYwKPI.delegate = self;  
    tabYwKPI.rowHeight = 60;  
    [self.view addSubview:tabYwKPI];  
   [tabYwKPIrelease];  
二、

UITableView 数据重新加载  

[tabYwKPI reloadData];  
三、

UITableView 各 Method 说明  

//Section 总数  
- (NSArray *)sectionIndexTitlesForTableView:(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 后的图片