Xcode Xib - iOS模拟器右下角的黑色边框

时间:2017-03-01 15:17:31

标签: objective-c xcode interface-builder xib

我正在使用Xcode 8.2.1,每当我将视图设置为XIB文件中的较小设备时,我都会在设备的右侧和底部获得这些后边框。还有一个问题,每当我选择iPhone 7 Plus然后在iPhone 7上运行时,界面的一部分被推离屏幕的右下角。目前所有内容都以Objective-C编码。

Device with black borders

更新

主屏幕。

View Stack View Windows

代码:

RootViewController的

#import "RootViewController.h"
#import "AppDelegate.h"
#import "DetailViewController.h"
- (void)viewDidLoad {
    [super viewDidLoad];
    if(CurrentLevel == 0) {
        NSArray *tempArray = [[NSArray alloc] init];
        self.tableDataSource = tempArray;
        [tempArray release];

        AppDelegate *AppDelegate = (AppDelegate *)[UIApplication sharedApplication].delegate;
        self.tableDataSource = (AppDelegate.data)[@"Rows"];

        self.navigationItem.title = @"Title";
    }
    else
        self.navigationItem.title = CurrentTitle;
}


- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
    NSDictionary *dictionary = (self.tableDataSource)[indexPath.row];
    NSArray *Children = dictionary[@"Children"];

    if(Children.count == 0) {
        DetailViewController *dvController = [[DetailViewController alloc] initWithNibName:@"DetailView" bundle:[NSBundle mainBundle]];
        [self.navigationController pushViewController:dvController animated:YES];
        dvController.CurrentTitle = dictionary[@"Title"];
        [dvController release];
    }
    else {
        RootViewController *rvController = [[RootViewController alloc] initWithNibName:@"RootViewController" bundle:[NSBundle mainBundle]];
        rvController.CurrentLevel += 1;
        rvController.CurrentTitle = dictionary[@"Title"];
        [self.navigationController pushViewController:rvController animated:YES];
        rvController.tableDataSource = Children;
        [rvController release];
    }
}

的AppDelegate

#import "AppDelegate.h"
#import "RootViewController.h"
- (void)applicationDidFinishLaunching:(UIApplication *)application {

NSString *Path = [NSBundle mainBundle].bundlePath;
NSString *DataPath = [Path stringByAppendingPathComponent:@"Master.plist"];

NSDictionary *tempDict = [[NSDictionary alloc] initWithContentsOfFile:DataPath];
self.data = tempDict;
[tempDict release];

[window setRootViewController:navigationController];
[window makeKeyAndVisible];
}

DetailViewController

#import "DetailViewController.h"
#import "AppDelegate.h"


@implementation DetailViewController
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {

UITableViewCell *cell = [tableView cellForRowAtIndexPath:indexPath];

if (cell.accessoryType == UITableViewCellAccessoryNone) {
    cell.accessoryType = UITableViewCellAccessoryCheckmark;

} else {
    cell.accessoryType = UITableViewCellAccessoryNone;
}
}

1 个答案:

答案 0 :(得分:2)

在任何地方设置"约束你可以"可能不是你想要的。看起来你已经设置了明确的宽度和高度。删除所有当前约束,而是设置值为0的顶部,底部,前导和尾随约束,并取消选中“约束到边距”。 (如果您希望tableview填充视图)。

Add Constraints

修改

在聊天中进行了一些讨论后,我发现这与AutoLayout约束无关。相反,由于您正在为主窗口使用XIB,因此它的大小明确调整为XIB中设置的大小。要正确调整大小,您需要做的就是告诉它屏幕的大小。 applicationDidFinishLaunching:中的任意位置,只需添加[window setFrame:UIScreen.mainScreen.bounds];,它就会调整为设备屏幕的大小。