我拼命嘗試2h現在在我的代碼中找到一個錯誤,這是負責不顯示我已經實現的SplitViewController。奇怪的是,沒有顯示編譯錯誤,並且所有鏈接和依賴關係似乎都是正確的。SplitViewController不顯示
第一次加載時屏幕上沒有任何東西顯示出來。但是當我旋轉設備時,我看到了正確的視圖。但是,即使所有視圖都已連接,但在啓動時根本沒有視圖。
我剛剛得到它的一部分工作...我發現與調試器,第一個視圖控制器未啓動時加載。所以視圖控制器陣列的拆分視圖它沒有填充一個初始視圖控制器...我該如何解決這個問題?
我檢查的第一部分是我的AppDelegate:
#import "AppDelegate.h"
#import "RootViewController.h"
@implementation AppDelegate
@synthesize window = _window;
@synthesize splitViewController = _splitViewController;
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
NSLog(@"%s %d", __PRETTY_FUNCTION__, __LINE__);
[[self window] addSubview:self.splitViewController.view];
[self.window makeKeyAndVisible];
return YES;
}
@end
的第一個視圖控制器
#import "FirstViewController.h"
@implementation FirstViewController
@synthesize toolbar;
#pragma mark -
#pragma mark View Lifecycle
- (void)viewDidUnload
{
[super viewDidUnload];
self.toolbar = nil;
}
#pragma mark -
#pragma mark Managing the Popover
- (void)showRootPopoverButtonItem:(UIBarButtonItem *)barButtonItem
{
NSMutableArray *itemsArray = [toolbar.items mutableCopy];
[itemsArray insertObject:barButtonItem atIndex:0];
[toolbar setItems:itemsArray animated:NO];
}
- (void)invalidateRootPopoverButtonItem:(UIBarButtonItem *)barButtonItem
{
NSMutableArray *itemsArray = [toolbar.items mutableCopy];
[itemsArray removeObject:barButtonItem];
[toolbar setItems:itemsArray animated:NO];
}
#pragma mark -
#pragma mark Rotation support
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
return YES;
}
@end
我檢查的第二部分是我的RootViewController的。事情是,當你點擊一個tableView Entry時,一個新的視圖控制器應該被加載並顯示出來。所以我沒有在我的應用程序委託中實例化VC,而是在「did select row」表中查看委託方法。
這是RootViewController的:
#import "RootViewController.h"
#import "FirstViewController.h"
#import "SecondViewController.h"
@implementation RootViewController
@synthesize popoverController, splitViewController, rootPopoverButtonItem;
#pragma mark -
#pragma mark View Lifecycle
- (void)viewDidLoad
{
NSLog(@"%s %d", __PRETTY_FUNCTION__, __LINE__);
[super viewDidLoad];
self.contentSizeForViewInPopover = CGSizeMake(310.0, self.tableView.rowHeight * 2.0);
}
- (void)viewDidUnload
{
NSLog(@"%s %d", __PRETTY_FUNCTION__, __LINE__);
[super viewDidUnload];
self.splitViewController = nil;
self.rootPopoverButtonItem = nil;
}
#pragma mark -
#pragma mark Rotation support
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation
{
NSLog(@"%s %d", __PRETTY_FUNCTION__, __LINE__);
return YES;
}
#pragma mark -
#pragma mark SplitViewController delegates
- (void)splitViewController:(UISplitViewController *)svc willHideViewController:(UIViewController *)aViewController withBarButtonItem:(UIBarButtonItem *)barButtonItem forPopoverController:(UIPopoverController *)pc
{
NSLog(@"%s %d", __PRETTY_FUNCTION__, __LINE__);
barButtonItem.title = @"PolyCube Prototypes";
self.popoverController = pc;
self.rootPopoverButtonItem = barButtonItem;
UIViewController <SubstitutableDetailViewController> *detailViewController = [splitViewController.viewControllers objectAtIndex:1];
[detailViewController showRootPopoverButtonItem:rootPopoverButtonItem];
}
- (void)splitViewController:(UISplitViewController *)svc willShowViewController:(UIViewController *)aViewController invalidatingBarButtonItem:(UIBarButtonItem *)barButtonItem
{
NSLog(@"%s %d", __PRETTY_FUNCTION__, __LINE__);
self.popoverController = nil;
self.rootPopoverButtonItem = nil;
UIViewController <SubstitutableDetailViewController> *detailViewController = [splitViewController.viewControllers objectAtIndex:1];
[detailViewController invalidateRootPopoverButtonItem:rootPopoverButtonItem];
}
#pragma mark -
#pragma mark Table View Data Source
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
NSLog(@"%s %d", __PRETTY_FUNCTION__, __LINE__);
return 2;
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
NSLog(@"%s %d", __PRETTY_FUNCTION__, __LINE__);
static NSString *CellIdentifier = @"RootViewControllerIdentifier";
UITableViewCell *cell = [self.tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {
cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier];
}
if (indexPath.row == 0) {
cell.textLabel.text = @"PolyCube 1";
}
else {
cell.textLabel.text = @"PolyCube 2";
}
return cell;
}
#pragma mark -
#pragma mark - Table View Selection
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
NSLog(@"%s %d", __PRETTY_FUNCTION__, __LINE__);
NSUInteger row = indexPath.row;
UIViewController <SubstitutableDetailViewController> *detailViewController = nil;
if (row == 0) {
FirstViewController *newDetailViewController = [[FirstViewController alloc] initWithNibName:@"FirstDetailView" bundle:nil];
detailViewController = newDetailViewController;
}
if (row == 1) {
SecondViewController *newDetailViewController = [[SecondViewController alloc] initWithNibName:@"SecondDetailView" bundle:nil];
detailViewController = newDetailViewController;
}
NSArray *vcs = [[NSArray alloc] initWithObjects:self.navigationController, detailViewController, nil];
splitViewController.viewControllers = vcs;
if (popoverController != nil) {
[popoverController dismissPopoverAnimated:YES];
}
if (rootPopoverButtonItem != nil) {
[detailViewController showRootPopoverButtonItem:self.rootPopoverButtonItem];
}
}
@end
我真的很感激了援助之手......我不知道去哪裏找了。我甚至檢查了所有的IB連接......我認爲沒有錯。但仍然只是一個白色的屏幕。
謝謝你這麼多 塞巴斯蒂安
要在任何地方加載NIB文件嗎? – craig1231 2012-01-01 21:06:42
以及我認爲是這樣的......我剛剛發現,splitviewcontroller.viewcontrollers數組最初沒有填充時加載....我該如何解決? 正如你所看到的,當我點擊一個tableview條目時,我更新了這個數組。但我記錄數組,同時調試顯示在NSLog中的對象....並有消息:NULL 所以我認爲應該有一種可能性,以「navcontroller和firstviewcontroller」初始化該數組... ...但我不知道如何實際 – konturgestaltung 2012-01-01 21:11:54