2017-03-01 40 views
0

我正在使用Xcode 8.2.1,每當將視圖設置爲較小的設備時,我都會在設備的右側和底部獲取這些背面邊框XIB文件。每當我選擇iPhone 7 Plus,然後在iPhone 7上運行時,界面的一部分被推離屏幕的右側和底部,也存在這樣的問題。目前所有東西都在Objective-C中編碼。Xcode Xib - iOS模擬器的黑色邊框右側和底部

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

當您的視圖小於設備的屏幕時會發生這種情況。您應該啓用自動佈局並添加限制以適合任何設備。 – Calc91

+0

@ Calc91我已經啓用了自動佈局,並且在任何地方都可以設置約束條件。 – Number1

回答

2

具有 「設置約束到處可以」 可能不是你想要的。看起來你已經設置了明確的寬度和高度。刪除所有當前的約束條件,而是設置值爲0的頂部,底部,前導和尾部約束,並取消選中「約束到邊距」(如果希望tableview填充視圖)。

Add Constraints

編輯:

在聊天經過一番討論後,我意識到,這已經無關自動版式的限制。相反,由於您正在爲主窗口使用XIB,因此它將根據XIB中設置的大小顯式調整大小。所有你需要做的正確的大小是告訴它什麼是你的屏幕的大小。在applicationDidFinishLaunching:的任何地方,只需添加[window setFrame:UIScreen.mainScreen.bounds];,它將調整到設備屏幕的大小。

+0

對於這些視圖,所有設置約束都變灰。當我說我爲上面的所有內容設置了約束時,這是爲了不同的視圖,它似乎不屬於這個1,因爲它在後面的堆棧中。 – Number1

+0

好的,我在你的更新中看到你的視圖不在視圖控制器內,所以是像我說的那樣添加約束是行不通的。你如何顯示有問題的視圖(不能正確縮放的視圖)?我在你的故事板截圖中沒有看到任何細節或關係。你是否實例化並手動預置它?代碼的樣子是什麼? –

+0

我沒有使用segues或關係,因爲我使用xib而不是storyboard。從我的理解我相信我正在實例化的意見。 – Number1