Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/objective-c/26.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ios 在运行时自定义UITableView标题节_Ios_Objective C_Iphone_Uitableview - Fatal编程技术网

Ios 在运行时自定义UITableView标题节

Ios 在运行时自定义UITableView标题节,ios,objective-c,iphone,uitableview,Ios,Objective C,Iphone,Uitableview,我已经使用下面的代码设置了标题背景,但我想在运行时单击添加为标题子视图的按钮时再次更改标题的颜色。 请给我提供代码,提前谢谢:) 您可以通过以下方式在运行时对其进行修改: 第一名: 您可以声明全局变量/属性,如: @property (nonatomic) UIView *tableHeader; 并将其设置在-(void)viewDidLoad 像 self.tableView.tableHeaderView=self.tableHeader 或者使用delagate: -(UIView *

我已经使用下面的代码设置了标题背景,但我想在运行时单击添加为标题子视图的按钮时再次更改标题的颜色。 请给我提供代码,提前谢谢:)


您可以通过以下方式在运行时对其进行修改:

第一名:

您可以声明全局变量/属性,如:

@property (nonatomic) UIView *tableHeader;
并将其设置在
-(void)viewDidLoad

self.tableView.tableHeaderView=self.tableHeader

或者使用delagate:

-(UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section
{
   return self.tableHeader;
}
并在您喜欢的任何地方修改它,但不要忘记重新加载表节标题,可能是
[tableView reloadSections:NSIndexSet withRowAnimation:UITableViewRowAnimation]就可以了

但是

在您的情况下,您可以在代理内部检索/获取tableHeader:

-(UIView*)表格视图:表格视图标题部分:部分

然后修改
tableHeaderView

或者简单地通过以下方式重新分配tableHeader:

yourTableView.tableHeaderView = tableHeaderView;
您可以单独使用
标题
,因为我可以看到它是一个全局变量。。 直接更改/更新它,如:

header.backgroundColor = [UIColor yourNewColor];
希望我帮了你。。祝你快乐,干杯

-(IBAction)onExpandButton:(UIButton *)sender { UIView *tmpView = [self.YourTableViewName headerViewForSection:sender.tag]; tmpView.backgroundColor = [UIColor colorWithPatternImage:[UIImage imageNamed:@"homeCellHeaderBackGround.png"]]; } -(iAction)onExpandButton:(UIButton*)发送器 { UIView*tmpView=[self.YourTableViewName headerViewForSection:sender.tag]; tmpView.backgroundColor=[UIColor-WithPatternImage:[UIImage-imageNamed:@“homeCellHeaderBackGround.png”]; }
-您从section方法的表视图标题中获得了视图。您可以在view上设置图像视图。

您可以通过以下代码更改节标题的背景色:

- (IBAction)onExpandButton:(id)sender {
   UIView *header = ((UIButton *)sender).superView;
   header.backgroundColor = <Whatever UIColor you like>;
   ...
}
-(iAction)onExpandButton:(id)发送方{
UIView*标题=((UIButton*)发送方;
header.backgroundColor=;
...
}

请检查此链接。也许你需要的就是这里。[在此处输入链接说明][1][1]:这就是我想要的:)抱歉,它不工作可能是发件人是一个按钮,我认为它没有连接到其超级视图,而是使用超级视图。发件人使用相同的逻辑工作正常。请参阅aboce kslcam答案,该答案根据我的要求运行良好:)所有这些信息都非常有用,可能我可以使其在其他场景中有用,但这次kslcam的答案运行良好。但我还是想感谢您提供的详细信息,谢谢:) -(IBAction)onExpandButton:(UIButton *)sender { UIView *tmpView = [self.YourTableViewName headerViewForSection:sender.tag]; tmpView.backgroundColor = [UIColor colorWithPatternImage:[UIImage imageNamed:@"homeCellHeaderBackGround.png"]]; }
- (IBAction)onExpandButton:(id)sender {
   UIView *header = ((UIButton *)sender).superView;
   header.backgroundColor = <Whatever UIColor you like>;
   ...
}