Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/ios/104.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_Uitableview - Fatal编程技术网

Ios 无法获取UITableView页脚

Ios 无法获取UITableView页脚,ios,objective-c,uitableview,Ios,Objective C,Uitableview,我正在尝试更改UITableView部分页脚的背景色。然而,我没有任何运气 UITableViewCell *cell = [_tableView cellForRowAtIndexPath:[NSIndexPath indexPathForRow:0 inSection:i]]; cell.backgroundColor = [UIColor redColor]; cell.textLabel.textColor = [UIColor redColor]; cell.detailTextLa

我正在尝试更改
UITableView
部分页脚的背景色。然而,我没有任何运气

UITableViewCell *cell = [_tableView cellForRowAtIndexPath:[NSIndexPath indexPathForRow:0 inSection:i]];

cell.backgroundColor = [UIColor redColor];
cell.textLabel.textColor = [UIColor redColor];
cell.detailTextLabel.textColor = [UIColor redColor];

UITableViewHeaderFooterView *header = [_tableView footerViewForSection:i];
[header setBackgroundColor:[UIColor redColor]];

第一部分——我在单元格中设置颜色的地方——正在工作。第二部分——我想设置页脚颜色的地方——不是。我做错了什么?

-footerViewForSection:
返回值吗?我猜它正在返回
nil
。是否在委托方法中为表视图提供页脚视图?如果你不是,它就不存在。如果是,则可以设置颜色。

您需要在
cellForRowAtIndexPath
方法和
footerViewForSection
方法内设置颜色

表格视图将根据需要请求单元格、页眉和页脚。对于细胞,它很可能会重复使用同一个细胞,这就是为什么你的细胞颜色似乎工作。然而,如果你做一些滚动,你会发现它可能停止工作

标题视图不起作用,因为您正在代码中请求一个视图,但该视图与表所使用的视图不同,因为它将请求自己的视图

因此,您应该在请求单元格、页眉或页脚时设置颜色


理想情况下,单元格/页眉/页脚配置应该由数据模型驱动。e、 g.在
cellforrowatinexpath
中,您应该为索引路径的数据模型条目创建合适的单元格。根据数据模型条目所需的颜色设置其颜色。然后,所有更改都会在数据模型上完成,然后重新加载受影响的部分和/或行。

因此以后无法更改页脚颜色?我已经在
footerViewForSection
中设置了背景色,但我想在操作后更改背景色。如更新的回答中所述,更改数据模型并重新加载受影响的indexPath。然后一切都会自行更新。因此,为每个条目添加一个状态,它定义了它应该是什么颜色,例如,这样以后就不可能更改页脚颜色了?我已经在
footerViewForSection
中设置了背景色,但我想在操作后更改背景色。您已经在-footerViewForSection:,或-tableView:viewForFooterSection:?不清楚是否已在-tableView:viewForFooterInstitution:delegate回调中为表视图创建了页脚。