首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >objc表格头隐藏表格?

objc表格头隐藏表格?
EN

Stack Overflow用户
提问于 2014-05-03 15:11:06
回答 1查看 28关注 0票数 0

我有一个tableView,其中添加了一个标题部分。不知怎么的头隐藏了行..。当我删除标题部分时,行是可见的。当我添加标题部分时,它会隐藏行。通常情况下,行应在标题部分之后可见。我没有胶水为什么这不能用..。

我有一个类似的tableView,在那里,它与相同的设置完美地工作,标题和行被显示。

表标题部分和行应同时可见。我如何做到这一点?代码下面的

LocationViewController.h

代码语言:javascript
复制
#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

代码语言:javascript
复制
#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
EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2014-05-03 15:56:03

它缺少一个委托方法。viewForHeaderInSection上的文档:.

返回的对象可以是UILabel或UIImageView对象,也可以是自定义视图。只有在还实现了tableView:heightForHeaderInSection:时,此方法才能正确工作。

所以再加上..。

代码语言:javascript
复制
- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section {
    return 174;
}
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/23446167

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档