2010-11-23 81 views
4

我有一个UITableView与定制单元,也是一个自定义标题,比如:移动头部时,在一个UITableView的编辑模式

-------------------- 
| Header   | 
-------------------- 
|  cell   | 
|  cell   | 
|  etc   | 

每当我把它进入编辑模式,以删除单元格,它看起来像这样

-------------------- 
| Header   | 
-------------------- 
- |  cell   
- |  cell   
- |  etc  

正如您所看到的,表格单元向右移动以腾出空间用于减号图标。但是,标题保持在相同的位置。我如何将标题移动到右侧,以匹配下面的单元格x-postion?

回答

-1

创建的编辑模式头不同的笔尖,然后只编辑时表现出来:

-(UIView *)tableView:(UITableView *)tv viewForHeaderInSection:(NSInteger)section { 
// CustomHeader creates the header view 
CustomHeader *tableHeader; 
if (self.tableView.editing) 
{ 
    tableHeader = (CustomHeader *)[CustomHeader headerFromNibNamed:@"CustomHeaderEditMode"];   
} else { 
    tableHeader = (CustomHeader *)[CustomHeader headerFromNibNamed:@"CustomHeader"]; 
} 
return tableHeader; 
} 
+0

使用笔尖这样是不是很高性能 - 加载它们是出了名的慢。 – memmons 2010-12-05 00:11:15

0

你可以在你的头添加一个标签 - (UIView的*)的tableView:(UITableView的*)电视viewForHeaderInSection:(NSInteger的)部分是这样的:

UILabel *label = [[UILabel alloc] initWithFrame:CGRectMake(x, y, self.tableView.bounds.size.width - 45,50)]; 

    label.font = [UIFont systemFontOfSize:14]; 
    label.backgroundColor = [UIColor greenColor]; 
    if(self.tableView.editing && section==0) 
    { 
     label.frame = CGRectMake(0,0,self.tableView.bounds.size.width,150); 
     NSString *NewSection = @"My new header message in edit mode d\n\n OK"; 
     label.text = NewSection; 
    } 
    else { 
     label.frame = CGRectMake(0,0,self.tableView.bounds.size.width,40); 
    label.text = [self tableView:tableView titleForHeaderInSection:section]; 
     } 

[sectionHeader addSubview:标号]; 然后将其添加到您的标题视图

希望它可以帮助你。

0
-(UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section{ 
UIView* viewObj = [[UIView alloc] initWithFrame:CGRectMake(0, 0, self.view.frame.size.width, 40]; 

UILabel *headerLabel = [[UILabel alloc] init];

headerLabel.font = [UIFont systemFontOfSize:14]; 
headerLabel.backgroundColor = [UIColor greenColor]; 
if(self.tableView.editing && section==0) 
{ 
    headerLabel.frame = CGRectMake(cellpositionX,0,self.tableView.bounds.size.width - cellpositionX,40); 
    NSString *NewSection = @"My new header message in edit mode d\n\n OK"; 
    headerLabel.text = NewSection; 
} 
else { 
    headerLabel.frame = CGRectMake(0,0,self.tableView.bounds.size.width,40); 
headerLabel.text = [self tableView:tableView titleForHeaderInSection:section]; 
    } 
[viewObj addSubview:headerLabel]; 
return viewObj;} 

在上面的代码可以传递在cellpositionX的x值。

每次当TableView开始和结束编辑。你需要重新加载的TableView

我希望这将解决您的问题

相关问题