2011-12-29 79 views
0

在我的iPhone应用程序,表视图::定制电池无法删除自定义标签

在表视图

我在一个单元中有两个标签..

  1. 为textLabel是默认。
  2. 自定义标签

数据从数组这是很好删除...

这里是代码..

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath 
{ 

    //Get the Log Id for the sections. From Section Array 
    int logID=0; 
    if(indexPath.row==0) 
    { 
     NSLog(@"Time Array %@",timeArray); 
     logID=[[[sectionArray objectAtIndex:indexPath.section] valueForKey:@"logID"] intValue]; 
     NSPredicate *p=[NSPredicate predicateWithFormat:@"logID==%d",logID]; 
     fillRows=nil; 
     fillRows= [[timeArray filteredArrayUsingPredicate:p] mutableCopy]; 
    } 



    static NSString *CellIdentifier = @"Cell"; 



    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier]; 
    if (cell == nil) { 
     cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleValue1 reuseIdentifier:CellIdentifier] autorelease]; 

    } 



//Show Current Time. 
//"If condition for not to go for Array Index Out of Bound". 
if(indexPath.row<[fillRows count]) 
{ 
//Log CurrentTime  
    cell.textLabel.text=[[fillRows objectAtIndex:indexPath.row] valueForKey:@"logCurrentTime"]; 
    [cell.textLabel setTextColor:[UIColor whiteColor]]; 
//Log Duration. 
    UILabel *lblDuration=[[[UILabel alloc] initWithFrame:CGRectMake(110, 11, 60, 21)] autorelease]; 
    [lblDuration setTextColor:[UIColor whiteColor]]; 
     [lblDuration setBackgroundColor:[UIColor clearColor]]; 
     [lblDuration setFont:[UIFont boldSystemFontOfSize:18]]; 
    lblDuration.text=[[fillRows objectAtIndex:indexPath.row] valueForKey:@"logDuration"]; 
     [cell.contentView addSubview:lblDuration]; 
    } 

    return cell; 
} 

感谢提前:)

回答

0

答案是这样的...... 就是为什么它是从粘在电池TE表中删除单元格的标签......

只看到我有评论两行代码......

当细胞==零..

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath 
    { 

     //Get the Log Id for the sections. From Section Array 

     static NSString *CellIdentifier = @"Cell"; 



     **UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier]; 
    // if (cell == nil) { 
      cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleValue1 reuseIdentifier:CellIdentifier] autorelease]; 

     // }** 



    /if(indexPath.row<[fillRows count]) 
    { 
    //Log CurrentTime  
     cell.textLabel.text=[[fillRows objectAtIndex:indexPath.row] valueForKey:@"logCurrentTime"]; 
     [cell.textLabel setTextColor:[UIColor whiteColor]]; 
    //Log Duration. 
     UILabel *lblDuration=[[[UILabel alloc] initWithFrame:CGRectMake(110, 11, 60, 21)] autorelease]; 
     [lblDuration setTextColor:[UIColor whiteColor]]; 
      [lblDuration setBackgroundColor:[UIColor clearColor]]; 
      [lblDuration setFont:[UIFont boldSystemFontOfSize:18]]; 
     lblDuration.text=[[fillRows objectAtIndex:indexPath.row] valueForKey:@"logDuration"]; 
      [cell.contentView addSubview:lblDuration]; 
     } 

     return cell; 
    } 
-1
if (cell == nil) { 
     cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleValue1 reuseIdentifier:CellIdentifier] autorelease]; 
    } 
if(indexPath.row<[fillRows count]) 
{ 
     [lblDuration setTextColor:[UIColor whiteColor]]; 
     [lblDuration setBackgroundColor:[UIColor clearColor]]; 
     [lblDuration setFont:[UIFont boldSystemFontOfSize:18]]; 
     [cell.contentView addSubview:lblDuration]; 

} 

试试这个..

-1

使用表格的委托方法为您的解决方案

  • (无效)的tableView:(UITableView的*)的tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath { 如果(editingStyle == UITableViewCellEditingStyleDelete) {[array removeObjectAtIndex:indexPath.row]; [tableview reloadData];}}

你得到你想要的。

+0

不,它不是这样的数组对象甚至删除后删除正确只是以前的自定义标签粘贴到该行... – 2011-12-29 05:26:57

+0

的Alloc细胞如下,看看。 static NSString * CellIdentifier = @“Cell”; UITableViewCell * cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier]; (cell == nil)cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleValue1 reuseIdentifier:CellIdentifier] autorelease];}如果(cell == nil){cell_device = – user1072740 2011-12-29 05:29:57