【问题标题】:How to bring a View to the top of a tableview content view in StoryBoard?如何将视图带到 StoryBoard 中的 tableview 内容视图的顶部?
【发布时间】:2015-09-08 08:29:45
【问题描述】:

我想建立一个关于用户的视图,显示用户信息和一些小功能。用户信息将显示在视图的顶部,并且有一个包含小功能的列表。

在情节提要中,我将TableView 拖到 ViewController,并拖了一个将显示用户信息的视图。当我将一个单元格推入表格视图时,情况就不同了。 Prototype Cells 会向上占据User Information view 的位置。

就像这样:

如何将用户信息视图带到Tableview 的顶部?

【问题讨论】:

    标签: ios objective-c uitableview storyboard


    【解决方案1】:

    如何先将单元格放在表格视图中,然后将视图放在表格视图中单元格上方,这是一个屏幕截图

    如您所见,UIView 是红色的,位于 tableview 内部,位于橙色的 cell 上方。

    或者您可以将UIView 完全放在tableview 上方,哪个更适合您。

    【讨论】:

    • 你可以这样做。
    • 它有效。先在tableview中拖动单元格,然后在Prototype cells上方拖动一个UIView。
    • 还有一点需要注意。在原型单元格上方放置UIView 后,您不能在prototype cell 上方放置任何组件,并且tableview 分为两个侧面:Prototype cell 部分和我们添加的部分View
    【解决方案2】:

    你可以使用bringSubviewToFront

    如果informationViewself.view 的子视图

    self.view.bringSubviewToFront(informationView)
    

    如果informationViewtableView 的子视图

    tableView.bringSubviewToFront(informationView)
    

    【讨论】:

    • 它不起作用。而且我认为它永远不会起作用,尽管在Reveal 应用程序中检查时cells 和我的information 视图处于相同的 UI 级别。
    • 你可以bringSubviewToFront from superview 每个创建新单元格。但这不是一个好方法。
    【解决方案3】:

    you 可以将任何视图作为标题视图放在 tablview 上

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

    }

    - (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section{
    
    
    searchBaar= [[UISearchBar alloc] initWithFrame:CGRectMake(0.0f, 0, SCREEN_WIDTH, 44.0f)];
    searchBaar.autocorrectionType = UITextAutocorrectionTypeNo;
    searchBaar.autocapitalizationType = UITextAutocapitalizationTypeNone;
    searchBaar.keyboardType = UIKeyboardTypeDefault;
    searchBaar.returnKeyType=UIReturnKeySearch;
    searchBaar.placeholder = @"Search";
    searchBaar.delegate = self;
    searchBaar.showsCancelButton = NO;
    searchBaar.tintColor=[UIColor blackColor];
    
    
    return searchBaar;
    

    }

    【讨论】:

    • 我想使用故事板来使用自动布局。或者有什么方法可以将标题视图放在情节提要中?
    • 您可以在 tableview 委托方法中简单地添加此代码
    猜你喜欢
    • 1970-01-01
    • 2012-06-27
    • 1970-01-01
    • 1970-01-01
    • 2017-10-05
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多