【问题标题】:Need to add a view as TableHeader?需要将视图添加为 TableHeader?
【发布时间】:2014-04-25 13:04:36
【问题描述】:

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

ACCRemainderView *header =  [ACCRemainderView customHeaderView];

[self.tableView setTableHeaderView:header];

在剩余视图中

+ (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;
    }
}

【问题讨论】:

  • 你的实际问题是什么?
  • 我将 Nib 文件加载为 TableView 标题,但我无法滚动并查看 tableview 详细信息。
  • 如果你的表格只有一个section,尝试使用Section Header
  • 格式精美的代码更容易阅读 :)

标签: ios uitableview xcode5


【解决方案1】:

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

【讨论】:

    【解决方案2】:

    设置tableHeaderView是最好的选择。我测试过,它有效。

    ViewForHeaderInSection 不能,因为在此视图标题的高度大于表格的高度。

    您不能滚动,我认为您的 tableView 与另一个视图重叠。

    - (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;
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-08-08
      • 1970-01-01
      • 1970-01-01
      • 2020-06-26
      相关资源
      最近更新 更多