如何在tableview视图中显示部分标题中的值数组?

时间:2012-01-09 14:40:11

标签: iphone objective-c uitableview

我有一个数组用于在表视图节标题中显示值。因此,为了在我使用– tableView:viewForHeaderInSection:的部分中显示这个值数组。最初它正确地显示了数组中的所有值,但是当我滚动tableview时,此部分值被更改而不是原始值。请指导我那里发生的事情。

我在tableview Viewfor标题

中写了这样的内容
UIView *headerView=[[UIView alloc]initWithFrame:CGRectMake(0, 0, 323, 50)];

//Background Image
///UIImageView *headerBg=[[UIImageView alloc]initWithImage:[UIImage imageNamed:@"arrow-button_50.png"]];
/// [headerView addSubview:headerBg];

//Button
UIButton *button=[UIButton buttonWithType:UIButtonTypeCustom];
button.frame=CGRectMake(0, 0, 215, 70);
button.tag=section+1;
[button addTarget:self action:@selector(buttonClicked:) forControlEvents:UIControlEventTouchUpInside];
[button setImage:[UIImage imageNamed:@"down_arrow.png"] forState:UIControlStateNormal];
[button setImage:[UIImage imageNamed:@"right_arrow.png"] forState:UIControlStateSelected];



if([[self.cellcountarray objectAtIndex:section] intValue]==0) 
    button.selected=YES;
else button.selected=NO;

[headerView addSubview:button];
NearbyPeople *obj=[self.sectionArray objectAtIndex:section];
NSLog(@"first name from section %@",[self.sectionArray objectAtIndex:0]);
UILabel *headerTitle=[[UILabel alloc]initWithFrame:CGRectMake(30, 15, 300, 30)];
[headerTitle setBackgroundColor:[UIColor clearColor]];
[headerTitle setFont:[UIFont fontWithName:@"Helvetica-Bold" size:15]];
[headerTitle setTextColor:[UIColor whiteColor]];
headerTitle.text=[NSString stringWithFormat:@"      %@",obj.FirstName];

NSLog(@"header text is %@",headerTitle.text);
///[headerTitle setText:obj.FirstName];
[headerView addSubview:headerTitle];
[headerTitle release];

提前感谢

1 个答案:

答案 0 :(得分:0)

这不是您的数据问题。因此,滚动结束后只需[self.tableview reloadData]

   - (void)scrollViewDidEndDragging:(UIScrollView *)scrollView willDecelerate:(BOOL)decelerate {

[self.tableView reloadData];

}

现在可能会有效。