2011-02-04 3 views
0

В настоящее время я играю с контроллером UISplitView, так как у меня есть некоторые из них, работающие в UITabBarController. После нескольких попыток, я, наконец, нашел удобный способ сделать это, единственная проблема, которую я получаю, - это то, что мне приходится вручную управлять своей детализацией и основным видом, хотя они настроены в IB и хорошо связаны.UISplitView Interface Builder nib объекты не выделены

Вот как я это делаю

Я инициализировать UITabBarController в моем MainWindow.xib и установить элементы TabBar.

Мой первый контроллер табуляции наследует от UISplitViewController и настроен с помощью xib. Вот реализация этого FirstViewController класса

#import "FirstSplitViewController.h" 
#import "MasterSplitViewController.h" 
#import "DetailSplitViewController.h" 


@implementation FirstSplitViewController 

@synthesize detailSplitViewController,masterSplitViewController; 



// Implement viewDidLoad to do additional setup after loading the view, typically from a nib. 
- (void)viewDidLoad { 
[super viewDidLoad]; 

/* 
masterSplitViewController = [[[MasterSplitViewController alloc] initWithNibName:@"MasterSplitViewController" bundle:nil] autorelease]; 
detailSplitViewController = [[[DetailSplitViewController alloc] initWithNibName:@"DetailSplitViewController" bundle:nil] autorelease]; 
*/ 

self.viewControllers = [NSArray arrayWithObjects:masterSplitViewController, detailSplitViewController , nil]; 
self.delegate = detailSplitViewController; 
} 

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation { 
// Overriden to allow any orientation. 
return YES; 
} 


- (void)didReceiveMemoryWarning { 
// Releases the view if it doesn't have a superview. 
[super didReceiveMemoryWarning]; 

// Release any cached data, images, etc. that aren't in use. 
} 


- (void)viewDidUnload { 
[super viewDidUnload]; 
// Release any retained subviews of the main view. 
// e.g. self.myOutlet = nil; 
} 


- (void)dealloc { 
[super dealloc]; 
} 


@end 

Вот мой MasterSplitview Реализация

#import "MasterSplitViewController.h" 


@implementation MasterSplitViewController 


// The designated initializer. Override if you create the controller programmatically and want to perform customization that is not appropriate for viewDidLoad. 
/* 
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil { 
self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil]; 
if (self) { 
    // Custom initialization. 
} 
return self; 
} 
*/ 


// Implement viewDidLoad to do additional setup after loading the view, typically from a nib. 
- (void)viewDidLoad { 
[super viewDidLoad]; 
} 



- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation { 
// Overriden to allow any orientation. 
return YES; 
} 


- (void)didReceiveMemoryWarning { 
// Releases the view if it doesn't have a superview. 
[super didReceiveMemoryWarning]; 

// Release any cached data, images, etc. that aren't in use. 
} 


- (void)viewDidUnload { 
[super viewDidUnload]; 
// Release any retained subviews of the main view. 
// e.g. self.myOutlet = nil; 
} 


- (void)dealloc { 
[super dealloc]; 
} 


@end 

и реализация моего DetailSplitViewController в

#import "DetailSplitViewController.h" 

@interface DetailSplitViewController() 
@property (nonatomic, retain) UIPopoverController *popoverController; 
- (void)configureView; 
@end 

@implementation DetailSplitViewController 

@synthesize toolbar, popoverController, detailItem, detailDescriptionLabel; 

/* 
When setting the detail item, update the view and dismiss the popover controller if it's showing. 
*/ 
- (void)setDetailItem:(id)newDetailItem { 
if (detailItem != newDetailItem) { 
    [detailItem release]; 
    detailItem = [newDetailItem retain]; 

    // Update the view. 
    [self configureView]; 
} 

if (self.popoverController != nil) { 
    [self.popoverController dismissPopoverAnimated:YES]; 
}   
} 

- (void)configureView { 
// Update the user interface for the detail item. 
// detailDescriptionLabel.text = [detailItem description]; 
} 

- (void)splitViewController: (UISplitViewController*)svc willHideViewController:(UIViewController *)aViewController withBarButtonItem:(UIBarButtonItem*)barButtonItem forPopoverController: (UIPopoverController*)pc 
{ 
barButtonItem.title = @"Root List"; 
NSMutableArray *items = [[toolbar items] mutableCopy]; 
[items insertObject:barButtonItem atIndex:0]; 
[toolbar setItems:items animated:YES]; 
[items release]; 
self.popoverController = pc; 
} 

// Called when the view is shown again in the split view, invalidating the button and popover controller. 
- (void)splitViewController: (UISplitViewController*)svc willShowViewController:(UIViewController *)aViewController invalidatingBarButtonItem:(UIBarButtonItem *)barButtonItem { 

NSMutableArray *items = [[toolbar items] mutableCopy]; 
[items removeObjectAtIndex:0]; 
[toolbar setItems:items animated:YES]; 
[items release]; 
self.popoverController = nil; 
} 


- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation { 
// Overriden to allow any orientation. 
return YES; 
} 


- (void)didReceiveMemoryWarning { 
// Releases the view if it doesn't have a superview. 
[super didReceiveMemoryWarning]; 

// Release any cached data, images, etc. that aren't in use. 
} 


- (void)viewDidUnload { 
[super viewDidUnload]; 
// Release any retained subviews of the main view. 
// e.g. self.myOutlet = nil; 
} 


- (void)dealloc { 
//[toolbar release]; 
[super dealloc]; 
} 

@end 

Everiting зацеплен в XIb годах, и проблема, которую я get - то, что когда мой FirstSplitViewController загружается из его xib, мои главные и подробные контроллеры splitview не (они связаны в IB). Если я Alloc их вручную, все работает как шарм (раскомментировав Alloc Инициализационные строчками ниже в моей FirstSplitViewController.m)

// Implement viewDidLoad to do additional setup after loading the view, typically from a nib. 
- (void)viewDidLoad { 
[super viewDidLoad]; 

/* 
masterSplitViewController = [[[MasterSplitViewController alloc] initWithNibName:@"MasterSplitViewController" bundle:nil] autorelease]; 
detailSplitViewController = [[[DetailSplitViewController alloc] initWithNibName:@"DetailSplitViewController" bundle:nil] autorelease]; 
*/ 

self.viewControllers = [NSArray arrayWithObjects:masterSplitViewController, detailSplitViewController , nil]; 
self.delegate = detailSplitViewController; 

} 

Так что мой вопрос, почему эти объекты are't загружены, когда XIB это? Это действительно первый раз, когда я должен сделать это вручную. Может быть, я что-то упустил.

Спасибо за любые ответы или советы

S-Mart

ответ

1

Я просто запустить через это же явление (я думаю). Я только начинаю полностью понимать, как работает интерфейс для создания интерфейса/Builder/heirarchy/view для iOS. Похоже, что переменные-члены, которые связаны через IBOutlet, не инициализируются до тех пор, пока не будет доступен экземпляр контроллера. Мой код был таким образом:

if(self.sectionOneViewController == nil) 
{ 
    SectionOneViewController *sectionOneView = [[SectionOneViewController alloc] 
         initWithNibName:@"SectionOne" 
         bundle:[NSBundle mainBundle]]; 
    self.sectionOneViewController = sectionOneView; 

    [sectionOneView release]; 
    //[self showSectionOne:sender]; 
} 

    [self.navigationController pushViewController:self.sectionOneViewController animated:YES]; 

[[UIApplication sharedApplication].keyWindow addSubview:self.sectionOneViewController.sectionOneTabController.view]; 

, если я сменил расположение последних 2-х линий оно будет иметь нулевой указатель на sectionOneTabController, если я не пересматривал вид. Я думаю, что с контроллером добавить ваше мнение необходимо, прежде чем ссылки .xib могут быть доступны.

+0

Большое спасибо и жаль долгое время, проверяя ваш ответ. Похоже, вы сказали, что ссылки xib требуют, чтобы представление загружалось до того, как они были доступны. – arex