2011-04-22 30 views
1

當我的UITableView加載'lineImage,顯示圖像在細胞結束時好,但當我滾動tableview行的一些圖像正在消失,一些剩餘。任何幫助?UITableViewCell - 圖像disaapearring當桌面滾動

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

    static NSString *CellIdentifier = @"Cell"; 


    UILabel *preferenceLabel; 
    UILabel *line1Label; 
    UILabel *line2Label; 
    UIImageView *lineImage; 

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

     lineImage = [[UIImageView alloc] initWithFrame:CGRectMake(10.0, 70.0, 320.0, 2.0)]; 
     lineImage.contentMode = UIViewContentModeScaleAspectFit; 
     lineImage.image = [UIImage imageNamed:@"seperator bar.png"]; 
     lineImage.tag = 1; 
     [cell.contentView addSubview:lineImage]; 
     [lineImage release]; 

     preferenceLabel = [appDelegate newLabelWithFrame:CGRectMake(10.0, 5.0, 234.0, 20.0) PrimaryColor:[UIColor blackColor] selectedColor:[UIColor blackColor] 
              fontSize:14.0 fontName:@"Verdana" bold:NO noOfLines:1]; 
     preferenceLabel.tag = 2; 
     [cell.contentView addSubview:preferenceLabel]; 
     [preferenceLabel release]; 

     line1Label=[appDelegate newLabelWithFrame:CGRectMake(10.0,20.0,234.0,20.0) PrimaryColor:[UIColor blueColor] selectedColor:[UIColor blackColor] fontSize:14.0 fontName:@"Verdana" bold:NO noOfLines:1]; 
     line1Label.tag = 3; 
     [cell.contentView addSubview:line1Label]; 
     [line1Label release]; 

     line2Label=[appDelegate newLabelWithFrame:CGRectMake(10.0,35.0,234.0,20.0) PrimaryColor:[UIColor blueColor] selectedColor:[UIColor blackColor] fontSize:14.0 fontName:@"Verdana" bold:NO noOfLines:1]; 
     line2Label.tag = 4; 
     [cell.contentView addSubview:line2Label]; 
     [line2Label release]; 

    } 
    else { 
      lineImage = (UIImageView *) [cell.contentView viewWithTag:1]; 
      preferenceLabel = (UILabel *)[cell.contentView viewWithTag:2]; 
      line1Label = (UILabel *)[cell.contentView viewWithTag:3]; 
      line2Label = (UILabel *)[cell.contentView viewWithTag:4]; 
    } 


    // Configure the cell... 

    cell.selectionStyle = UITableViewCellSelectionStyleNone; 


    preferenceLabel.text = @"Preference Label "; 
    [email protected]"Line1 Label"; 
    [email protected]"Line2 Label"; 

    return cell; 


} 
+0

raval:嘗試刪除這個塊'if(cell == nil)'並且讓我知道請。 – 2011-04-22 14:41:21

回答

0

當您使用[UIImage的imageNamed:]你沒有將其釋放,因爲你沒有自己的頁頭...

+0

他不這樣做。只是一個令人困惑的變量命名方案 – 2011-04-22 14:21:29

+0

糟糕,你是對的... – Aymarick 2011-04-22 14:22:44

+0

他不釋放lineImage.image(我看到);他正在釋放lineImage;但這是他分配的UIImageView。 – Dave 2011-04-22 14:24:49

0

你確定你的lineImage完全在於你的細胞的範圍內? (你的rowHeight是> = 72.0)如果不是,你的單元格可能會重疊一些內容並遮住lineImage。地方代碼之後

cell.selectionStyle = UITableViewCellSelectionStyleNone; 
0

lineImage.image = [UIImage imageNamed:@"seperator bar.png"]; 

我覺得insted的加入爲imageview的分隔符的我是通過使用這種快樂。 mailSubscritionTable.separatorColor = [UIColor blueColor]; tableView.tableFooterView = [[[UIView alloc] init] autorelease];

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

    static NSString *CellIdentifier = @"Cell"; 


    UILabel *preferenceLabel; 
    UILabel *line1Label; 
    UILabel *line2Label; 
    UIImageView *lineImage; 

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

     lineImage = [[UIImageView alloc] initWithFrame:CGRectMake(10.0, 70.0, 320.0, 2.0)]; 
     lineImage.contentMode = UIViewContentModeScaleAspectFit; 
//removed a line of code and added at the end 
     lineImage.tag = 1; 
     [cell.contentView addSubview:lineImage]; 
     [lineImage release]; 

     preferenceLabel = [appDelegate newLabelWithFrame:CGRectMake(10.0, 5.0, 234.0, 20.0) PrimaryColor:[UIColor blackColor] selectedColor:[UIColor blackColor] 
              fontSize:14.0 fontName:@"Verdana" bold:NO noOfLines:1]; 
     preferenceLabel.tag = 2; 
     [cell.contentView addSubview:preferenceLabel]; 
     [preferenceLabel release]; 

     line1Label=[appDelegate newLabelWithFrame:CGRectMake(10.0,20.0,234.0,20.0) PrimaryColor:[UIColor blueColor] selectedColor:[UIColor blackColor] fontSize:14.0 fontName:@"Verdana" bold:NO noOfLines:1]; 
     line1Label.tag = 3; 
     [cell.contentView addSubview:line1Label]; 
     [line1Label release]; 

     line2Label=[appDelegate newLabelWithFrame:CGRectMake(10.0,35.0,234.0,20.0) PrimaryColor:[UIColor blueColor] selectedColor:[UIColor blackColor] fontSize:14.0 fontName:@"Verdana" bold:NO noOfLines:1]; 
     line2Label.tag = 4; 
     [cell.contentView addSubview:line2Label]; 
     [line2Label release]; 

    } 
    else { 
      lineImage = (UIImageView *) [cell.contentView viewWithTag:1]; 
      preferenceLabel = (UILabel *)[cell.contentView viewWithTag:2]; 
      line1Label = (UILabel *)[cell.contentView viewWithTag:3]; 
      line2Label = (UILabel *)[cell.contentView viewWithTag:4]; 
    } 


    // Configure the cell... 

    cell.selectionStyle = UITableViewCellSelectionStyleNone; 

    lineImage.image = [UIImage imageNamed:@"seperator bar.png"];//changes 
    preferenceLabel.text = @"Preference Label "; 
    [email protected]"Line1 Label"; 
    [email protected]"Line2 Label"; 

    return cell; 


} 

請看看上面的代碼行,我在代碼中做了小的修改並更新。

相關問題