如何在viewForHeaderInSection的tableview中动态更改标题标题?
我需要在tableview标题中设置标题名称。 IM在如何在viewForHeaderInSection的tableview中动态更改标题标题?
- (UIView *) tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section function
{
IView *headerView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, tableView.bounds.size.width, 30)];
UILabel *lbl_header = [[UILabel alloc]initWithFrame:CGRectMake(12, 0, tableView.bounds.size.width, 30)];
lbl_header.tag=1000001;
lbl_header.backgroundColor = [UIColor clearColor];
lbl_header.textColor = [UIColor colorWithRed:204.0/255 green:204.0/255 blue:204.0/255 alpha:1.0];
lbl_header.font = [UIFont fontWithName:@"Helvetica-Regular" size:20];
//// get the title name from subclass view controller
HOAViewController *obj_hoaview_controll = [[HOAViewController alloc]init];
[obj_hoaview_controll fun_get_login_email_id];
lbl_header.text = str_email_id1;//[udf_value objectForKey:@"StrEmailGet"];
if (section == 0)
{
[headerView setBackgroundColor:[UIColor colorWithRed:102.0/255 green:102.0/255 blue:102.0/255 alpha:1.0]];
//lbl_header.text = [udf_value objectForKey:@"StrEmailGet"];
}
else
{
[headerView setBackgroundColor:[UIColor clearColor]];
}
[headerView addSubview:lbl_header];
return headerView;
}
由于使用此代码的答复....
使用titleForHeaderInSection,从UITableViewDataSource协议。确保numberOfSectionsInTableView
也得到很好的实施。
样品:
- (NSString *)tableView:(UITableView *)tableView titleForHeaderInSection:(NSInteger)section
{
if (section == 0)
return @"Title1";
else if (section == 1)
return @"Title2";
}
标题名称从一个类到另一个类在这里代码为HOAViewController * obj_hoaview_controll = [[HOAViewController alloc] init]; [obj_hoaview_controll fun_get_login_email_id] ;. – Raj 2013-03-20 17:46:19
这可以使用你的逻辑来处理,但在上面的功能,它会工作。如果是,请将答案标记为正确(复选标记) – 2013-03-20 17:51:07
标题名称从一个类到另一个类,最后在lbl_header.text对象中。我从子类获得标题名称,以及如何重新加载viewForHeaderInSection函数或在该类中调用viewForHeaderInSection。 – Raj 2013-03-20 17:52:08
你的问题还不清楚。您发布的代码已经设置了标题的标题('lbl_header.text = str_email_id1;')。你真正问的是什么问题? – rmaddy 2013-03-20 17:30:37
str_email_id1是字符串对象,并在其中存储标题名称。 – Raj 2013-03-20 17:49:10