我有一个tableView,在其中添加了一个标题部分。不知怎的,标题隐藏了行。。。当我删除标题部分时,行是可见的。当我添加标题部分时,它会隐藏行。通常情况下,排应在集管段之后可见。我没有胶水为什么这不起作用。。。
我有一个类似的tableView,在那里它可以完美地使用相同的设置,显示标题和行。
表格标题部分和行应同时可见。我该怎么做代码下方:
LocationViewController.h
#import <UIKit/UIKit.h>
#import "SingletonClass.h"
#import "WebApi.h"
#import <AFNetworking/UIImageView+AFNetworking.h>
@interface LocationViewController : UITableViewController
@property (nonatomic, strong) SingletonClass *sshare;
@property (nonatomic, strong) WebApi *swebapi;
@property (strong, nonatomic) IBOutlet UITableView *tableView;
@property (strong, nonatomic) NSString *locationID;
@end
LocationViewController.m
#import "LocationViewController.h"
@interface LocationViewController ()
@end
@implementation LocationViewController
- (id)initWithStyle:(UITableViewStyle)style
{
self = [super initWithStyle:style];
if (self) {
}
return self;
}
- (void)vinit {
self.sshare = [SingletonClass sharedInstance];
self.swebapi = [[WebApi alloc] init];
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(handleNotification:) name:@"reloadDetails" object:nil ];
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(handleNotification:) name:NFlocationReload object:nil ];
}
- (void)viewDidLoad
{
[self vinit];
[self.navigationController setNavigationBarHidden:NO animated:NO];
[super viewDidLoad];
self.tableView.tableFooterView = [[UIView alloc] init];
[self getData];
}
- (void)viewDidAppear:(BOOL)animated
{
[self.navigationController setNavigationBarHidden:NO animated:NO];
}
-(void)handleNotification:(NSNotification *)message {
if ([[message name] isEqualToString:@"reloadDetails"]) {
[self.tableView reloadData];
}
if ([[message name] isEqualToString:NFlocationReload]) {
DLog(@"%@, lData", self.sshare.lData);
[self.tableView reloadData];
}
}
- (void)didReceiveMemoryWarning
{
[super didReceiveMemoryWarning];
}
#pragma mark - Table view data source
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
return 1;
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
return self.sshare.lData.count;
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"locationCell" forIndexPath:indexPath];
NSString *foo = [NSString stringWithFormat:@"row %ld", (long)indexPath.row];
cell.textLabel.text = foo;
DLog(@"logged: %@", foo);
cell.backgroundColor = [UIColor purpleColor];
return cell;
}
-(void)getData {
[self.swebapi getLocationStream:self.locationID];
}
#pragma mark table header image and size
- (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section {
UIImageView *BGView = [[UIImageView alloc] initWithFrame:CGRectMake(0, 10, 320, 174)];
[BGView setBackgroundColor:[UIColor whiteColor]];
UIImageView *imageView = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, 320, 169)];
[imageView setBackgroundColor:[UIColor orangeColor]];
imageView.contentMode = UIViewContentModeScaleAspectFill;
[imageView setClipsToBounds:YES];
NSString *photoURL;
if (self.sshare.imageDetails) {
photoURL = self.sshare.imageDetails.url
[imageView setImageWithURL:[NSURL URLWithString:photoURL] placeholderImage:[UIImage imageNamed:@"foo.jpg"]];
[BGView addSubview:imageView];
}
return BGView;
}
@end
它缺少一个委托方法。来自viewForHeaderInSection
上的文档:。。。
返回的对象可以是UILabel或UIImageView对象,以及自定义视图。只有当tableView:heightForHeaderInSection:也实现了。
所以添加。。。
- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section {
return 174;
}