我有一个tableView,我添加了一个标题部分。不知何故,标题隐藏了行...当我删除标题部分时,行是可见的。当我添加标题部分时,它会隐藏行。通常,标题部分后面的行应该是可见的。我没有胶水,为什么这不起作用......
我有一个类似的tableView,它可以完美地使用相同的设置,显示标题和行。
表头部分和行应同时可见。我怎么能这样做? 代码下方:
#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
#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
答案 0 :(得分:0)
它缺少委托方法。来自viewForHeaderInSection
上的文档:...
返回的对象可以是UILabel或UIImageView对象,也可以是 自定义视图。此方法仅在以下时正常工作 tableView:heightForHeaderInSection:也已实现。
所以添加......
- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section {
return 174;
}