如何在表视图视图中显示段中标题的值数组?
问题描述:
我有一个数组用于显示表视图节标题中的值。因此,要在第i部分中使用– 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];
感谢
答
这不是你的data.So的问题,您只需滚动[self.tableview reloadData]
- (void)scrollViewDidEndDragging:(UIScrollView *)scrollView willDecelerate:(BOOL)decelerate {
[self.tableView reloadData];
}
结束后
可能会现在工作。
请。显示。一些。码。 – ferostar 2012-01-09 14:41:12
你能发表一些代码吗? – blake305 2012-01-09 14:41:56
你能更具体吗?它是什么类型的视图?什么样的价值?他们如何改变?你的代码是什么样的? – 2012-01-09 14:41:57