ios - 在 iOS 9 中,如果为页面使用 UIViewController 以外的类,我如何创建约束以避免破坏状态和/或标签栏?

标签 ios ios9 statusbar

所有指南都建议调整顶部布局指南以避免破坏状态栏。但是,如果页面是使用 UIViewController 以外的 View Controller 创建的(例如,如果它是使用 UITableViewController 创建的,因为页面主要是 TableView )则它没有布局指南。我怎样才能避免状态栏?

最佳答案

我发现 UITableViewController 比它的值(value)更麻烦,就像这个人:How do I make my iOS7 UITableViewController NOT appear under the top status bar?

现在,当我实现 TableView 时,我发现将 TableView 设为 UIViewController 的属性会更容易,然后将委托(delegate)和数据源职责设置为 UIViewController。从那里您可以根据需要自定义它。您可以使用状态栏设置(推断、无、黑色等)等 Storyboard 选项,但根据我的经验,我发现将 UITableView 放入 UIViewController 中效果最佳。

标题示例:

@interface MyViewController : UIViewController <UITableViewDelegate, UITableViewDataSource>

@property (weak, nonatomic) IBOutlet UITableView *myTableView;

Controller 中的示例代码

@synthesize myTableView;
//**** Table View Delegate and Data Source ****//

-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    static NSString *myCellIdentifier = @"myCell";
    MyTableViewCell *cell = (MyTableViewCell *)[myTableView dequeueReusableCellWithIdentifier:myCellIdentifier];
    //Customize the cell
    return cell;
}

-(NSInteger)tableView:(UITableView*)tableView numberOfRowsInSection:(NSInteger)section
{
    return [myDataSource count];
}

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    //perform some action on click
}

没有 NavigationController 的 UITableViewController 的另一个例子和状态栏的问题:iOS 7: UITableView shows under status bar

关于ios - 在 iOS 9 中,如果为页面使用 UIViewController 以外的类,我如何创建约束以避免破坏状态和/或标签栏?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34550551/

相关文章:

ios - 图像未从 iOS 中的文件路径加载

authentication - iOS - Facebook SDK v3.24.1 登录屏幕为空白,使用 FBSessionLoginBehaviorForcingWebView 时除外

xcode - xcrun simctl status_bar 在 xcode 12 中不起作用

ios - 如何在 Swift 中的 "model"组件中设置委托(delegate) View Controller 类

IOS7 UIPickerView如何隐藏选择指示符

ios - 是否可以在获得初始权限后向 UIUserNotificationCategory 添加新操作?

ios - 在 swift 2 中调用电话的按钮?

iOS 7 - 隐藏 subview Controller 上的状态栏

c# - 在 Windows 窗体上获取和显示网络信号强度

ios - 如何在 Firestore 中构建搜索列表?