I would like to dynamically change an image in my tableview custom section header cell once the image finished being downloaded. However I do not how to get the reference to the section header cell. Is there an equivalent function for getting the header cell like there is for getting the table view cell using the function cellForRowAtIndexPath?
I tried but this is for the row. I need an equivalent for section header
if let cellToUpdate = tableView.cellForRowAtIndexPath(indexPath) as? ListingTableViewCell {
cellToUpdate.imageView.image = image!
}
To customize your headers, you can override the following method from the UITableViewDataSource
.
- (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section
It works pretty much cellForRowAtIndexPath
. You juste have to create your view and return it. Here is an example to set a UIImage
as header of section 0 :
- (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section
{
UIImageView *imageView = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, 10, 10)];
switch (section) {
case 0:
imageView.image = [UIImage imageNamed:@"image"];
return imageView;
break;
default:
break;
}
return [[UIView alloc] init];
}
Just set tags for section header view.
- (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section{
UIView *view = [UIView new];
view.backgroundColor = [UIColor orangeColor];
view.tag = section;
return view;
}
Then use tag to get the section header view.
NSInteger section2 = 2;
UIView *sectionHeader = [self.tableView viewWithTag:section2];
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.