所有指南都建议调整顶部布局指南以避免破坏状态栏。但是,如果页面是使用 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/