详解iOS App中UITableView的创建与内容刷新

2020-01-15 14:09:21王冬梅

iOS,App,UITableView

设置cell的行高


- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath 
{ 
 return 70; 
} 

设置cell的隔行换色


- (void)tableView:(UITableView *)tableView willDisplayCell:(UITableViewCell *)cell forRowAtIndexPath:(NSIndexPath *)indexPath 
{ 
 if ([indexPath row] % 2 == 0) { 
  cell.backgroundColor = [UIColor blueColor]; 
 } else { 
  cell.backgroundColor = [UIColor greenColor]; 
 } 
} 

iOS,App,UITableView

当选择指定的cell时,弹出UIAlertView显示选择的内容


- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath 
{ 
  
 NSString *msg = [[NSString alloc] initWithFormat:@"你选择的是:%@",[self.dataList objectAtIndex:[indexPath row]]]; 
 UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"提示" message:msg delegate:self cancelButtonTitle:@"确定" otherButtonTitles:nil, nil]; 
 [msg release]; 
 [alert show]; 
} 

iOS,App,UITableView

滑动选择的行后删除


- (void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath 
{ 
 NSLog(@"执行删除操作"); 
} 

iOS,App,UITableView

 

UITableView的刷新:


[self.tableView reloadData];