2014-05-03 24 views
0

我的TableViewCell沒有在第一次加載內容後,我將滾動了表,它會顯示完整的view.I在tableView中有五個部分(section = 1)有這個問題。UITableViewCell第一次沒有正確加載標籤

我在這裏附上我的代碼。

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{ 
    UITableViewCell *cell=[super tableView:tableView cellForRowAtIndexPath:indexPath]; 
    return cell; 
} 

在負載視圖 On view load

後向上滾動

After scroll up

+0

後設定值到單元[的tableView reloadData]; –

+0

pastie.org/9135727是的,我已經設置 – moosa0709

+0

我認爲代碼不會重用單元格。 –

回答

1
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView 
{ 
    return 2; 
} 
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section 
{ 
    if (section == 0) 
    { 
     return 10; 
    } 
    else if (section == 1) 
    { 
     return 10; 
    } 
    else 
    { 
     return 0; 
    } 
} 
- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section; 
{ 
    if(section == 0) 
    { 
     return 40; 
    } 
    else if(section == 1) 
    { 
     return 40; 
    } 
    else 
    { 
     return 0; 
    } 
} 
-(UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section 
{ 
    UIView *View=[[UIView alloc]initWithFrame:CGRectMake(0,0,768,40)]; 
    View.backgroundColor=[UIColor colorWithRed:211.0/255.0 green:211.0/255.0 blue:211.0/255.0 alpha:1.0]; 

    UILabel *lbl_title=[[UILabel alloc]initWithFrame:CGRectMake(10,0,700,40)]; 
    lbl_title.backgroundColor=[UIColor clearColor]; 
    lbl_title.font= [UIFont fontWithName:@"ArialMT" size:20]; 
    lbl_title.textColor =[UIColor colorWithRed:0 green:0 blue:0 alpha:1.0]; 
    if (section == 0) 
    { 
     [email protected]"Used"; 
    } 
    else if (section == 1) 
    { 
     [email protected]"Expiring"; 
    } 
    [View addSubview:lbl_title]; 
    [lbl_title release]; 

    return View; 
} 


- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath 
{ 
    return 80; 
} 

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath 
{ 
    NSString *CellIdentifier = [NSString stringWithFormat:@"cell %d",indexPath.section]; 

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

     if (indexPath.section == 0) 
     { 
      UILabel *lbl=[[UILabel alloc]init]; 
      lbl.frame=CGRectMake(180,10, 360, 60); 
      lbl.backgroundColor=[UIColor clearColor]; 
      lbl.textColor = [UIColor blackColor]; 
      lbl.numberOfLines = 3; 
      lbl.font = [UIFont fontWithName:@"ArialMT" size:18]; 
      lbl.text = @""; 
      [cell.contentView addSubview:lbl]; 
      [lbl release]; 
     } 
     else if (indexPath.section == 1) 
     { 
      UILabel *lbl=[[UILabel alloc]init]; 
      lbl.frame=CGRectMake(180,10, 360, 60); 
      lbl.backgroundColor=[UIColor clearColor]; 
      lbl.textColor = [UIColor blackColor]; 
      lbl.numberOfLines = 3; 
      lbl.font = [UIFont fontWithName:@"ArialMT" size:18];; 
      lbl.text = @""; 
      [cell.contentView addSubview:lbl]; 
      [lbl release]; 
     } 
     cell.selectionStyle = UITableViewCellSelectionStyleNone; 
    } 
    return cell; 
} 
0
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath 
{ 
    static NSString *cellIdentifier = @"cell"; 
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:cellIdentifier]; 
    cell.textLabel.text = arrayValues[indexPath.row]; 
    return cell; 
} 
+0

http://pastie.org/9135727請檢查此 – moosa0709

相關問題