首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >需要添加一个视图作为TableHeader吗?

需要添加一个视图作为TableHeader吗?
EN

Stack Overflow用户
提问于 2014-04-25 21:04:37
回答 2查看 58关注 0票数 1

是否可以加载高度为672的视图作为TableView标题?我添加了它,但我无法滚动和查看表格视图单元格的详细信息。我已经用过代码了

代码语言:javascript
复制
ACCRemainderView *header =  [ACCRemainderView customHeaderView];

[self.tableView setTableHeaderView:header];

在剩余部分视图中

代码语言:javascript
复制
+ (id)customHeaderView
{
    ACCRemainderView *customView = [[[NSBundle mainBundle] loadNibNamed:@"ACCRemainderView" owner:nil options:
                                     nil] lastObject];

    //make sure customView is not nil or the wrong class!        
    if ([customView isKindOfClass:[ACCRemainderView class]]) {
        return customView;
    } else {
        return nil;
    }
}
EN

回答 2

Stack Overflow用户

发布于 2014-04-25 21:23:19

尝试在UITableViewController中实现- (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section并返回[ACCRemainderView customHeaderView]

票数 1
EN

Stack Overflow用户

发布于 2014-04-25 21:33:07

设置tableHeaderView是最好的选择。我测试过了,它工作正常。

ViewForHeaderInSection不能,因为此视图头的高度大于表的高度。

你不能滚动,我想你的tableView被另一个视图重叠了。

代码语言:javascript
复制
- (void)viewDidLoad
{
[super viewDidLoad];

_tableView.dataSource = self;
_tableView.delegate = self;
}

- (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section
{
NSString *title=[self tableView:tableView titleForHeaderInSection:section];
if ( !title )
    return nil;


UIView *view = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, tableView.frame.size.width, 500)];
view.backgroundColor = [UIColor greenColor];
return view;
}

- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section
{
return 500;
}


- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
return 2;
}

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
return 2;
}

- (NSString *)tableView:(UITableView *)tableView titleForHeaderInSection:(NSInteger)section
{
return @"abcd";
}

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
return 50;
}


- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *CellIdentifier = @"Cell";
UITableViewCell *cell = (UITableViewCell*)[tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {
    cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier];
}
cell.textLabel.text = @"a";
return cell;
}
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/23294012

复制
相关文章

相似问题

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