2011-07-19 24 views
0

我在表單元格中使用自定義標籤。每當我再次訪問此頁面時,標籤文本變得越來越暗,就像它表現爲覆蓋。 我該如何解決這個問題?iphone:問題重裝表數據

- (void)viewWillAppear:(BOOL)animated { 

    NSFetchRequest *request = [[NSFetchRequest alloc] init]; 

     NSEntityDescription *entity = [NSEntityDescription entityForName:@"Note" inManagedObjectContext:context]; 
     [request setEntity:entity]; 
     [request release];  
     [self.tableView reloadData]; 
    } 

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

     static NSString *CellIdentifier = @"Cell"; 

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

     // Set up the cell... 
     Note *noteItem = [resultController objectAtIndexPath:indexPath]; 

     //[cell.textLabel setText:[noteItem noteTitle]];  
     //[cell.detailTextLabel setText:[dateFormatter stringFromDate:[noteItem creationDate]]]; 
     [cell setAccessoryType:UITableViewCellAccessoryDisclosureIndicator]; 
     cell.accessoryView=[[UIImageView alloc] initWithImage:[UIImage imageNamed:@"arrow.png"]]; 

     UILabel *newLabel = [[UILabel alloc] initWithFrame:CGRectMake(5, 5, 200, 19)]; 
     newLabel.text = [noteItem noteTitle]; 
     [newLabel setBackgroundColor:[UIColor clearColor]]; 
     [cell addSubview:newLabel]; 
     [newLabel release]; 

     UILabel *detailLabel = [[UILabel alloc] initWithFrame:CGRectMake(5, 20, 200, 26)]; 
     detailLabel.text = [dateFormatter stringFromDate:[noteItem creationDate]]; 
     [detailLabel setFont:[UIFont fontWithName:@"Helvetica" size:12.0]]; 
     [detailLabel setBackgroundColor:[UIColor clearColor]]; 
     [cell addSubview:detailLabel]; 
     [detailLabel release]; 

     [cell setBackgroundColor:[UIColor clearColor]]; 
     [cell setAlpha:0.6]; 
     return cell; 
    } 

回答

0

你的cellForRowAtIndexPath方法應該是喜歡 -

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

     static NSString *CellIdentifier = @"Cell"; 

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

      nameLabelFrame = CGRectMake(5, 5, 200, 19); 
     countLabelFrame = CGRectMake(5, 20, 200, 26); 
      UILabel *lblTemp; 
      lblTemp = [[UILabel alloc] initWithFrame:nameLabelFrame]; 
     lblTemp.tag = 1; 
     [cell.contentView addSubview:lblTemp]; 
     [lblTemp release]; 


     lblTemp = [[UILabel alloc] initWithFrame:countLabelFrame]; 
     lblTemp.tag = 2; 
     [cell.contentView addSubview:lblTemp]; 
     [lblTemp release]; 

     } 

     // Set up the cell... 
     Note *noteItem = [resultController objectAtIndexPath:indexPath]; 

UILabel *newLabel = (UILabel *)[cell viewWithTag:1]; 
     newLabel.text = [noteItem noteTitle]; 
     [newLabel setBackgroundColor:[UIColor clearColor]]; 



     UILabel *detailLabel = (UILabel *)[cell viewWithTag:2]; 
     detailLabel.text = [dateFormatter stringFromDate:[noteItem creationDate]]; 
     [detailLabel setFont:[UIFont fontWithName:@"Helvetica" size:12.0]]; 
     [detailLabel setBackgroundColor:[UIColor clearColor]]; 



     [cell setAccessoryType:UITableViewCellAccessoryDisclosureIndicator]; 
     cell.accessoryView=[[UIImageView alloc] initWithImage:[UIImage imageNamed:@"arrow.png"]]; 



     [cell setBackgroundColor:[UIColor clearColor]]; 
     [cell setAlpha:0.6]; 
     return cell; 
    } 
0

您應該檢查cell == nil。如果是這樣,那麼再次添加所有標籤,否則,它們已經被添加。

2

if (cell == nil) { 
      cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:CellIdentifier] autorelease]; 
     } 

創建的UILabel,並指定這個條件之外及其價值

+0

確定..現在的工作? – iProgrammer

+0

是的,它現在 – Heena