2011-02-10 3 views
3

Я используюTableView HeaderSection распределения памяти

- (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section 
{  
    customView = [[UIView alloc] initWithFrame:CGRectMake(0.0, 0.0, 320.0, 24.0)];//custom view  
   // create the button object 
   headerLabel = [[UILabel alloc]initWithFrame:CGRectMake(10, 3, tableView.bounds.size.width, 18)];//header label  
    headerLabel.backgroundColor = [UIColor colorWithPatternImage: [UIImage imageWithContentsOfFile: [[NSBundle mainBundle] pathForResource: @"section" ofType: @"png"]]];  
    customView.backgroundColor = [UIColor colorWithPatternImage: [UIImage imageWithContentsOfFile: [[NSBundle mainBundle] pathForResource: @"section" ofType: @"png"]]];  
   headerLabel.textColor = [UIColor whiteColor];//text color of header label    
    headerLabel.font = [UIFont fontWithName:@"HelveticaNeue" size:15];//font of header label   
    headerLabel.font = [UIFont boldSystemFontOfSize:15];  
   headerLabel.frame = CGRectMake(0.0, 0.0, 320.0, 24.0);//frame of header label 

    if(searching)//checking searching {  
     headerLabel.text = @"  Search Results";//searching results as a text of header label  
    }  
    else {  
     if(section == 0)//checking which section is chosen {  
      headerLabel.text = @"  Sponsored";//sponsored as header label 
     } 
     else {  
      headerLabel.text = @"  Unsponsored";//un sponsored as header label   
     } 
    } 

    if(searching)//checking searching {     
     headerLabel.text = @"  Sök resultat";//sok resultant text as a header label     
    } 
    else {  
     if(section == 0)//checking which section is chosen {  
      headerLabel.text = @"  Sponsrade";//sponsorade as text of header label 
     }      
     else   { 
      headerLabel.text = @"  Un Sponsrade";//usponsrade as text of header label 
     } 
    }     

   [customView addSubview:headerLabel];//header label as a subview  
    //NSLog(@"endOfviewForHeaderInSection");   
    //[headerLabel release];     
   return customView;//returning custom view 

    [customView release];  
    //NSLog(@"endOfviewForHeaderInSection"); 
} 

в разделе заголовка в виде таблицы, чтобы разделить таблицу на две секции, когда я прокрутке таблицы просмотра вверх и вниз распределения памяти увеличивается очень быстро, но вместо того, используя вышеупомянутый код в разделе заголовка, нет распределения памяти, и приложение работает отлично. Но есть необходимость использования вышеописанного кода в разделе заголовка, я не могу удалить код из заголовка, и я хочу также уменьшить распределение памяти. Есть ли другой способ разобраться в проблеме.

Спасибо заранее.

+1

Пожалуйста, просмотрите форматирование кода, которое вы публикуете! – abatishchev

ответ

4
- (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section 
{  
    //NSLog(@"startOfviewForHeaderInSection"); 
    // create the parent view that will hold header Label 

    customView = nil; 

    [customView release]; 

    headerLabel =nil; 

    [headerLabel release]; 

    customView = [[UIView alloc]init]; 

    headerLabel = [[UILabel alloc]init]; 

    // customView = [[UIView alloc] initWithFrame:CGRectMake(0.0, 0.0, 320.0, 24.0)];//custom view 

    // create the button object 
// headerLabel = [[UILabel alloc]initWithFrame:CGRectMake(10, 3, tableView.bounds.size.width, 18)];//header label 



    //customView.frame = CGRectMake(0.0, 0.0, 320.0, 24.0); 

    //headerLabel.frame = CGRectMake(0.0, 0.0, 320.0, 24.0);//frame of header label 
    //DetailedCoupon *detailedcouponObj = [[DetailedCoupon alloc]init];//object of detailed 

    headerLabel.backgroundColor = [UIColor colorWithPatternImage: [UIImage imageWithContentsOfFile: [[NSBundle mainBundle] pathForResource: @"section" ofType: @"png"]]]; 

    //customView.backgroundColor = [detailedcouponObj getColor:@"D7D8D1"];//background color 

    customView.backgroundColor = [UIColor colorWithPatternImage: [UIImage imageWithContentsOfFile: [[NSBundle mainBundle] pathForResource: @"section" ofType: @"png"]]]; 

    //headerLabel.backgroundColor = [UIColor blackColor]; 
    // headerLabel.opaque = NO;//opaque header label 

    headerLabel.textColor = [UIColor whiteColor];//text color of header label 

    // headerLabel.highlightedTextColor = [UIColor whiteColor];//highlighted text color of header label 

    // headerLabel.font = [UIFont boldSystemFontOfSize:20];//font of header label 

    headerLabel.font = [UIFont fontWithName:@"HelveticaNeue" size:15];//font of header label 

    headerLabel.font = [UIFont boldSystemFontOfSize:15]; 

    headerLabel.frame = CGRectMake(0.0, 0.0, 320.0, 24.0);//frame of header label 

    NSUserDefaults *pref = [NSUserDefaults standardUserDefaults];//object of NSUserDefault 

    NSString *storeLanguage = [pref objectForKey:@"language"];//store language of string type 

    if ([storeLanguage isEqualToString:@"English"])//comparison of language choosed 
    { 

     if(searching)//checking searching 

     { 

      headerLabel.text = @" Search Results";//searching results as a text of header label 

     } 

     else { 

      if(section == 0)//checking which section is choosed 

      { 

       headerLabel.text = @" Sponsored";//sponsored as header label 

      } 

      else 

      { 

       headerLabel.text = @" Unsponsored";//un sponsored as header label 

      } 

     } 
    } 

    else 
     { 

      if(searching)//checking searching 

      { 


       headerLabel.text = @" Sök resultat";//sok resultant text as a header label 

      } 

      else { 

       if(section == 0)//checking which section is choosed 

       { 

        headerLabel.text = @" Sponsrade";//sponsorade as text of header label 

       } 

       else 

       { 

        headerLabel.text = @" Un Sponsrade";//usponsrade as text of header label 

       } 

      } 

     } 

    [customView addSubview:headerLabel];//header label as a subview 

    //NSLog(@"endOfviewForHeaderInSection"); 

    //[headerLabel release]; 

    storeLanguage = nil; 

    [storeLanguage release]; 

    return customView;//returning custom view 

    [pref release]; 

    [customView release]; 

    //NSLog(@"endOfviewForHeaderInSection"); 

} 
0

Ваш код плохо отформатирован в вашем сообщении и трудно следовать.

Но я вижу, что вы можете протекать в customView с тех пор, как вы вернетесь, прежде чем выпустить его. Вместо этого вы можете авторекламой, прежде чем вернуться.

Одна из возможностей, если это верхняя часть таблицы, заключается в том, чтобы вместо этого использовать заголовок таблицы table, который, как я считаю, вам не нужно постоянно выделять, как viewForHeaderInSection. Вы также можете попробовать создавать и кэшировать новое, а не создавать его снова и снова.

Смежные вопросы