UITableView常见问题

 1. UITableViewController中,默认的tableView是无法修改其Frame的。

    若要修改需要自己创建一个UITableView的对象。加入到self.view中

 2. IOS6中 UITableViewStyleGrouped类型无法设置背景颜色,需要修改BackgroundView属性

- (void)viewDidLoad
{  
   ITableView *tableV = [[UITableView alloc]initWithFrame:CGRectMake(0, 0, 320, 460) style:UITableViewStyleGrouped];
    tableV.backgroundView =nil;  //这里!
    tableV.backgroundColor = [UIColor clearColor];
    tableV.dataSource =self;
    tableV.delegate =self;
  [self.view addSubview:tableV];

}


 3.UITableViewStyleGrouped类型的Cell会有边线,非常乱,需要修改Cell的BackgroundView

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    static NSString * cellIndef = @"cellIndef";
    
    UITableViewCell * cell = [tableView dequeueReusableCellWithIdentifier:cellIndef];
    
    if (!cell) {
        cell = [[[UITableViewCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellIndef]autorelease];
        cell.selectionStyle = UITableViewCellSelectionStyleNone;
        [cell setBackgroundView:nil]; //这里
    }
    return cell;
}


 4. 不是直接使用UITableViewController时,比如创建了一个UITableView对象,Cell的选择效果是不会消失的,需要在选择方法中做一些处理

   

-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath  
{
   [tableView deselectRowAtIndexPath:[tableView   indexPathForSelectedRow] animated:YES];   //这里

}

 5. 在table内容为空时显示空白的视图,取代默认的。

- (void)viewDidLoad
{
  ..
  tableView.separatorStyle = UITableViewCellSeparatorStyleNone;
  ..
}

-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    if ([array count]>0)
    {
    tableView.separatorStyle=UITableViewCellSeparatorStyleSingleLine;
    }
    return [array count];
}

你可能感兴趣的:(ios,ios,iPhone,UITableView)